Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Use photo-local dates for timeline sorting

Manav Rathica729e40b40b
diff --git a/web/apps/albums/src/public-album/components/FileListWithViewer.tsx b/web/apps/albums/src/public-album/components/FileListWithViewer.tsx
index d8ca335ea0..913aecd8db 100644
--- a/web/apps/albums/src/public-album/components/FileListWithViewer.tsx
+++ b/web/apps/albums/src/public-album/components/FileListWithViewer.tsx
@@ -11,7 +11,7 @@ import { styled } from "@mui/material";
import { isSameDay } from "ente-base/date";
import { formattedDate } from "ente-base/i18n-date";
import type { EnteFile } from "ente-media/file";
-import { fileCreationTime, fileFileName } from "ente-media/file-metadata";
+import { fileCreationPhotoDate, fileFileName } from "ente-media/file-metadata";
import { t } from "i18next";
import { useCallback, useEffect, useMemo, useState } from "react";
import AutoSizer from "react-virtualized-auto-sizer";
@@ -233,7 +233,7 @@ const Container = styled("div")`
* See: [Note: Timeline date string]
*/
const fileTimelineDateString = (file: EnteFile) => {
- const date = new Date(fileCreationTime(file) / 1000);
+ const date = fileCreationPhotoDate(file);
return isSameDay(date, new Date())
? t("today")
: isSameDay(date, new Date(Date.now() - 24 * 60 * 60 * 1000))
diff --git a/web/apps/albums/src/public-album/components/TripLayout/MobileCover.tsx b/web/apps/albums/src/public-album/components/TripLayout/MobileCover.tsx
index afe825a711..1397e1952c 100644
--- a/web/apps/albums/src/public-album/components/TripLayout/MobileCover.tsx
+++ b/web/apps/albums/src/public-album/components/TripLayout/MobileCover.tsx
@@ -11,9 +11,7 @@ interface MobileCoverProps {
export const MobileCover = memo<MobileCoverProps>(
({ journeyData, albumTitle, coverImageUrl }) => {
const sortedData = [...journeyData].sort(
- (a, b) =>
- new Date(a.timestamp).getTime() -
- new Date(b.timestamp).getTime(),
+ (a, b) => a.timestamp - b.timestamp,
);
const firstData = sortedData[0];
const lastData = sortedData[sortedData.length - 1];
diff --git a/web/apps/albums/src/public-album/components/TripLayout/MobileTimelineLocation.tsx b/web/apps/albums/src/public-album/components/TripLayout/MobileTimelineLocation.tsx
index 32e32cab91..da29dbc6d2 100644
--- a/web/apps/albums/src/public-album/components/TripLayout/MobileTimelineLocation.tsx
+++ b/web/apps/albums/src/public-album/components/TripLayout/MobileTimelineLocation.tsx
@@ -17,9 +17,7 @@ export const MobileTimelineLocation = memo<MobileTimelineLocationProps>(
if (!firstPhoto) return null;
const sortedData = [...journeyData].sort(
- (a, b) =>
- new Date(a.timestamp).getTime() -
- new Date(b.timestamp).getTime(),
+ (a, b) => a.timestamp - b.timestamp,
);
const firstData = sortedData[0];
if (!firstData) return null;
diff --git a/web/apps/albums/src/public-album/components/TripLayout/MobileTripStarted.tsx b/web/apps/albums/src/public-album/components/TripLayout/MobileTripStarted.tsx
index 9273bb29fb..69d1b56b12 100644
--- a/web/apps/albums/src/public-album/components/TripLayout/MobileTripStarted.tsx
+++ b/web/apps/albums/src/public-album/components/TripLayout/MobileTripStarted.tsx
@@ -11,9 +11,7 @@ export const MobileTripStarted = memo<MobileTripStartedProps>(
({ onRef, journeyData }) => {
// Get the first photo's date
const sortedData = [...journeyData].sort(
- (a, b) =>
- new Date(a.timestamp).getTime() -
- new Date(b.timestamp).getTime(),
+ (a, b) => a.timestamp - b.timestamp,
);
const firstPhoto = sortedData[0];
const firstPhotoDate = firstPhoto
diff --git a/web/apps/albums/src/public-album/components/TripLayout/TimelineLocation.tsx b/web/apps/albums/src/public-album/components/TripLayout/TimelineLocation.tsx
index 371a660523..0503f5f810 100644
--- a/web/apps/albums/src/public-album/components/TripLayout/TimelineLocation.tsx
+++ b/web/apps/albums/src/public-album/components/TripLayout/TimelineLocation.tsx
@@ -28,9 +28,7 @@ export const TimelineLocation = memo<TimelineLocationProps>(
const firstPhoto = cluster[0];
if (!firstPhoto) return null;
const sortedData = [...journeyData].sort(
- (a, b) =>
- new Date(a.timestamp).getTime() -
- new Date(b.timestamp).getTime(),
+ (a, b) => a.timestamp - b.timestamp,
);
const firstData = sortedData[0];
if (!firstData) return null;
diff --git a/web/apps/albums/src/public-album/components/TripLayout/TripCover.tsx b/web/apps/albums/src/public-album/components/TripLayout/TripCover.tsx
index 9f8d65dbe0..b59effc2de 100644
--- a/web/apps/albums/src/public-album/components/TripLayout/TripCover.tsx
+++ b/web/apps/albums/src/public-album/components/TripLayout/TripCover.tsx
@@ -12,9 +12,7 @@ interface TripCoverProps {
export const TripCover = memo<TripCoverProps>(
({ journeyData, albumTitle, coverImageUrl }) => {
const sortedData = [...journeyData].sort(
- (a, b) =>
- new Date(a.timestamp).getTime() -
- new Date(b.timestamp).getTime(),
+ (a, b) => a.timestamp - b.timestamp,
);
const firstData = sortedData[0];
const lastData = sortedData[sortedData.length - 1];
diff --git a/web/apps/albums/src/public-album/components/TripLayout/hooks/useFileViewer.ts b/web/apps/albums/src/public-album/components/TripLayout/hooks/useFileViewer.ts
index 99904802d7..ec5a7936a7 100644
--- a/web/apps/albums/src/public-album/components/TripLayout/hooks/useFileViewer.ts
+++ b/web/apps/albums/src/public-album/components/TripLayout/hooks/useFileViewer.ts
@@ -1,5 +1,5 @@
import { type EnteFile } from "ente-media/file";
-import { fileCreationTime } from "ente-media/file-metadata";
+import { fileCreationPhotoSortTime } from "ente-media/file-metadata";
import { useCallback, useState } from "react";
import type { JourneyPoint } from "../types";
@@ -26,9 +26,17 @@ export const useFileViewer = ({
clusterFileIds.includes(file.id),
);
- // Sort cluster files by creation time
+ // Sort cluster files by the local photo creation date shown in the UI.
+ const sortTimeByFile = new Map<EnteFile, number>();
+ const sortTimeForFile = (file: EnteFile) => {
+ const cached = sortTimeByFile.get(file);
+ if (cached != undefined) return cached;
+ const t = fileCreationPhotoSortTime(file);
+ sortTimeByFile.set(file, t);
+ return t;
+ };
const sortedClusterFiles = [...clusterFiles].sort(
- (a, b) => fileCreationTime(a) - fileCreationTime(b),
+ (a, b) => sortTimeForFile(a) - sortTimeForFile(b),
);
// Find the index of the clicked photo in the cluster files
diff --git a/web/apps/albums/src/public-album/components/TripLayout/index.tsx b/web/apps/albums/src/public-album/components/TripLayout/index.tsx
index da395c146a..bd1579d518 100644
--- a/web/apps/albums/src/public-album/components/TripLayout/index.tsx
+++ b/web/apps/albums/src/public-album/components/TripLayout/index.tsx
@@ -250,14 +250,10 @@ export const TripLayout: React.FC<TripLayoutProps> = ({
// Sort clusters by their earliest timestamp to maintain chronological order
const sortedClusters = clusters.sort((a, b) => {
const earliestA = Math.min(
- ...a.map((p) =>
- new Date(p.timestamp).getTime(),
- ),
+ ...a.map((p) => p.timestamp),
);
const earliestB = Math.min(
- ...b.map((p) =>
- new Date(p.timestamp).getTime(),
- ),
+ ...b.map((p) => p.timestamp),
);
return earliestA - earliestB;
});
diff --git a/web/apps/albums/src/public-album/components/TripLayout/types.ts b/web/apps/albums/src/public-album/components/TripLayout/types.ts
index b1a482a1c8..50f12d6de7 100644
--- a/web/apps/albums/src/public-album/components/TripLayout/types.ts
+++ b/web/apps/albums/src/public-album/components/TripLayout/types.ts
@@ -3,7 +3,12 @@ export interface JourneyPoint {
lng: number;
name: string;
country: string;
- timestamp: string;
+ /**
+ * Millisecond sort/display key in the local photo timeline.
+ *
+ * This is not an absolute UTC timestamp.
+ */
+ timestamp: number;
image: string;
fileId: number;
}
diff --git a/web/apps/albums/src/public-album/components/TripLayout/utils/dataProcessing.ts b/web/apps/albums/src/public-album/components/TripLayout/utils/dataProcessing.ts
index 7e38cade1a..fd2f3a9700 100644
--- a/web/apps/albums/src/public-album/components/TripLayout/utils/dataProcessing.ts
+++ b/web/apps/albums/src/public-album/components/TripLayout/utils/dataProcessing.ts
@@ -1,7 +1,7 @@
import { downloadManager } from "@/public-album/download/services/download-manager";
import { type EnteFile } from "ente-media/file";
import {
- fileCreationTime,
+ fileCreationPhotoSortTime,
fileFileName,
fileLocation,
} from "ente-media/file-metadata";
@@ -46,9 +46,7 @@ export const processPhotosData = ({
lng: location.longitude,
name: finalName,
country: finalCountry,
- timestamp: new Date(
- fileCreationTime(file) / 1000,
- ).toISOString(),
+ timestamp: fileCreationPhotoSortTime(file),
image: "",
fileId: file.id,
});
@@ -58,10 +56,7 @@ export const processPhotosData = ({
}
}
- photoData.sort(
- (a, b) =>
- new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime(),
- );
+ photoData.sort((a, b) => a.timestamp - b.timestamp);
return { photoData, hasLocationData: photoData.length > 0 };
};
diff --git a/web/apps/albums/src/public-album/media/utils/sort-files.ts b/web/apps/albums/src/public-album/media/utils/sort-files.ts
index 2602198c36..c56c1af158 100644
--- a/web/apps/albums/src/public-album/media/utils/sort-files.ts
+++ b/web/apps/albums/src/public-album/media/utils/sort-files.ts
@@ -1,5 +1,5 @@
import type { EnteFile } from "ente-media/file";
-import { fileCreationTime } from "ente-media/file-metadata";
+import { fileCreationPhotoSortTime } from "ente-media/file-metadata";
/**
* Sort the given list of {@link EnteFile}s in place.
@@ -13,14 +13,22 @@ import { fileCreationTime } from "ente-media/file-metadata";
* is first.
*/
export const sortFiles = (files: EnteFile[], sortAsc = false) => {
- // Sort based on the time of creation time of the file.
+ // Sort based on the local photo creation date shown in the UI.
//
- // For files with same creation time, sort based on the time of last
+ // For files with same creation date, sort based on the time of last
// modification.
const factor = sortAsc ? -1 : 1;
+ const sortTimeByFile = new Map<EnteFile, number>();
+ const sortTimeForFile = (file: EnteFile) => {
+ const cached = sortTimeByFile.get(file);
+ if (cached != undefined) return cached;
+ const t = fileCreationPhotoSortTime(file);
+ sortTimeByFile.set(file, t);
+ return t;
+ };
return files.sort((a, b) => {
- const at = fileCreationTime(a);
- const bt = fileCreationTime(b);
+ const at = sortTimeForFile(a);
+ const bt = sortTimeForFile(b);
return at == bt
? factor *
(b.metadata.modificationTime - a.metadata.modificationTime)
diff --git a/web/apps/embed/src/components/EmbedFileListWithViewer.tsx b/web/apps/embed/src/components/EmbedFileListWithViewer.tsx
index 0dae26a292..7fa46ac807 100644
--- a/web/apps/embed/src/components/EmbedFileListWithViewer.tsx
+++ b/web/apps/embed/src/components/EmbedFileListWithViewer.tsx
@@ -6,7 +6,7 @@ import { formattedDate } from "ente-base/i18n-date";
import { FileViewer } from "ente-gallery/components/viewer/FileViewer";
import type { Collection } from "ente-media/collection";
import type { EnteFile } from "ente-media/file";
-import { fileCreationTime } from "ente-media/file-metadata";
+import { fileCreationPhotoDate } from "ente-media/file-metadata";
import {
GalleryItemsHeaderAdapter,
GalleryItemsSummary,
@@ -138,7 +138,7 @@ export const EmbedFileListWithViewer: React.FC<
const Container = styled("div")({ flex: 1, width: "100%" });
const fileTimelineDateString = (file: EnteFile) => {
- const date = new Date(fileCreationTime(file) / 1000);
+ const date = fileCreationPhotoDate(file);
return isSameDay(date, new Date())
? t("today")
: isSameDay(date, new Date(Date.now() - 24 * 60 * 60 * 1000))
diff --git a/web/apps/photos/src/components/Collections/CollectionMapDialog.tsx b/web/apps/photos/src/components/Collections/CollectionMapDialog.tsx
index f362c4e5e7..29b071e4cf 100644
--- a/web/apps/photos/src/components/Collections/CollectionMapDialog.tsx
+++ b/web/apps/photos/src/components/Collections/CollectionMapDialog.tsx
@@ -23,7 +23,7 @@ import { uniqueFilesByID } from "ente-gallery/utils/file";
import { type Collection } from "ente-media/collection";
import { type EnteFile } from "ente-media/file";
import {
- fileCreationTime,
+ fileCreationPhotoSortTime,
fileLocation,
ItemVisibility,
} from "ente-media/file-metadata";
@@ -134,7 +134,7 @@ interface MapComponents {
* - fileId: Unique identifier for the photo file
* - lat: Latitude coordinate of the photo location
* - lng: Longitude coordinate of the photo location
- * - timestamp: Unix timestamp (milliseconds) of when the photo was created
+ * - timestamp: Millisecond sort key in the local photo timeline.
*/
interface MapIndexPoint {
@@ -149,7 +149,6 @@ interface MapPhotoPoint {
lng: number;
name: string;
country: string;
- timestamp: string;
image: string;
fileId: number;
}
@@ -162,8 +161,9 @@ interface MapPhotoPoint {
*/
/**
- * The small payload we attach to a point: fileId points to the photo, and timestamp keeps
- * enough context for sorting or choosing the freshest item in a cluster.
+ * The small payload we attach to a point: fileId points to the photo, and
+ * timestamp keeps enough local-photo timeline context for sorting or choosing
+ * the freshest item in a cluster.
*/
interface MapPointProperties {
fileId: number;
@@ -329,7 +329,7 @@ const buildMapIndexPoints = async (files: EnteFile[]) => {
const loc = fileLocation(file);
if (!loc) continue;
- const timestamp = fileCreationTime(file);
+ const timestamp = fileCreationPhotoSortTime(file);
points.push({
fileId: file.id,
lat: loc.latitude,
@@ -743,7 +743,7 @@ function useMapData(
//If the file was previously hidden then adding it back to the existing list.
const loc = fileLocation(file);
if (loc) {
- const timestamp = fileCreationTime(file);
+ const timestamp = fileCreationPhotoSortTime(file);
mapPoints = [
...prev.mapPoints,
{
@@ -2065,9 +2065,6 @@ const MapClusters = React.memo(function MapClusters({
lng,
name: "",
country: "",
- timestamp: new Date(
- leaf.properties.timestamp / 1000,
- ).toISOString(),
image: "",
fileId: leaf.properties.fileId,
};
diff --git a/web/apps/photos/src/components/Collections/PickCoverPhotoDialog.tsx b/web/apps/photos/src/components/Collections/PickCoverPhotoDialog.tsx
index 2a898b582b..012c521e25 100644
--- a/web/apps/photos/src/components/Collections/PickCoverPhotoDialog.tsx
+++ b/web/apps/photos/src/components/Collections/PickCoverPhotoDialog.tsx
@@ -16,7 +16,7 @@ import { ut } from "ente-base/i18n";
import { formattedDate } from "ente-base/i18n-date";
import type { Collection } from "ente-media/collection";
import type { EnteFile } from "ente-media/file";
-import { fileCreationTime } from "ente-media/file-metadata";
+import { fileCreationPhotoDate } from "ente-media/file-metadata";
import { FileType } from "ente-media/file-type";
import { t } from "i18next";
import React, { useCallback, useEffect, useId, useMemo, useState } from "react";
@@ -310,7 +310,7 @@ const createSingleSelection = (
}) as SelectedState;
const fileTimelineDateString = (file: EnteFile) => {
- const date = new Date(fileCreationTime(file) / 1000);
+ const date = fileCreationPhotoDate(file);
return isSameDay(date, new Date())
? t("today")
: isSameDay(date, new Date(Date.now() - 24 * 60 * 60 * 1000))
diff --git a/web/apps/photos/src/components/FileListWithViewer.tsx b/web/apps/photos/src/components/FileListWithViewer.tsx
index 5dd07d3aeb..1024c912c4 100644
--- a/web/apps/photos/src/components/FileListWithViewer.tsx
+++ b/web/apps/photos/src/components/FileListWithViewer.tsx
@@ -14,7 +14,7 @@ import {
import { downloadAndSaveFiles } from "ente-gallery/services/save";
import type { Collection } from "ente-media/collection";
import type { EnteFile } from "ente-media/file";
-import { fileCreationTime, fileFileName } from "ente-media/file-metadata";
+import { fileCreationPhotoDate, fileFileName } from "ente-media/file-metadata";
import { useSettingsSnapshot } from "ente-new/photos/components/utils/use-snapshot";
import { moveToTrash } from "ente-new/photos/services/collection";
import type { CollectionSummary } from "ente-new/photos/services/collection-summary";
@@ -458,7 +458,7 @@ const MapIcon = styled("img")<{ $isDarkMode: boolean }>(
* See: [Note: Timeline date string]
*/
const fileTimelineDateString = (file: EnteFile) => {
- const date = new Date(fileCreationTime(file) / 1000);
+ const date = fileCreationPhotoDate(file);
return isSameDay(date, new Date())
? t("today")
: isSameDay(date, new Date(Date.now() - 24 * 60 * 60 * 1000))
diff --git a/web/packages/gallery/utils/file.ts b/web/packages/gallery/utils/file.ts
index ec3807c265..e3bedd1aef 100644
--- a/web/packages/gallery/utils/file.ts
+++ b/web/packages/gallery/utils/file.ts
@@ -1,5 +1,5 @@
import type { EnteFile } from "ente-media/file";
-import { fileCreationTime } from "ente-media/file-metadata";
+import { fileCreationPhotoSortTime } from "ente-media/file-metadata";
/**
* Sort the given list of {@link EnteFile}s in place.
@@ -13,14 +13,22 @@ import { fileCreationTime } from "ente-media/file-metadata";
* is first.
*/
export const sortFiles = (files: EnteFile[], sortAsc = false) => {
- // Sort based on the time of creation time of the file.
+ // Sort based on the local photo creation date shown in the UI.
//
- // For files with same creation time, sort based on the time of last
+ // For files with same creation date, sort based on the time of last
// modification.
const factor = sortAsc ? -1 : 1;
+ const sortTimeByFile = new Map<EnteFile, number>();
+ const sortTimeForFile = (file: EnteFile) => {
+ const cached = sortTimeByFile.get(file);
+ if (cached != undefined) return cached;
+ const t = fileCreationPhotoSortTime(file);
+ sortTimeByFile.set(file, t);
+ return t;
+ };
return files.sort((a, b) => {
- const at = fileCreationTime(a);
- const bt = fileCreationTime(b);
+ const at = sortTimeForFile(a);
+ const bt = sortTimeForFile(b);
return at == bt
? factor *
(b.metadata.modificationTime - a.metadata.modificationTime)
diff --git a/web/packages/media/file-metadata.ts b/web/packages/media/file-metadata.ts
index 68968317fa..233e3cc4bd 100644
--- a/web/packages/media/file-metadata.ts
+++ b/web/packages/media/file-metadata.ts
@@ -475,7 +475,8 @@ export const fileFileName = (file: EnteFile) =>
* This function handles files with edited dates.
*
* While sometimes the epoch timestamp is the correct value to use, it is also
- * possible that {@link fileCreationPhotoDate} might be more appropriate.
+ * possible that {@link fileCreationPhotoDate} or
+ * {@link fileCreationPhotoSortTime} might be more appropriate.
*/
export const fileCreationTime = (file: EnteFile) =>
file.pubMagicMetadata?.data.editedTime ?? file.metadata.creationTime;
@@ -494,6 +495,15 @@ export const fileCreationPhotoDate = (file: EnteFile) =>
file.metadata.creationTime,
);
+/**
+ * Return a millisecond sort key for the file's creation date in the
+ * hypothetical "timezone of the photo".
+ *
+ * This is a photo-local comparable value, not an absolute UTC timestamp.
+ */
+export const fileCreationPhotoSortTime = (file: EnteFile) =>
+ fileCreationPhotoDate(file).getTime();
+
/**
* Return the GPS coordinates (if any) present in the given {@link EnteFile}.
*
diff --git a/web/packages/new/photos/services/ml/cluster.ts b/web/packages/new/photos/services/ml/cluster.ts
index d4e34378dc..ebd5b0b516 100644
--- a/web/packages/new/photos/services/ml/cluster.ts
+++ b/web/packages/new/photos/services/ml/cluster.ts
@@ -2,7 +2,7 @@ import { assertionFailed } from "ente-base/assert";
import { newNonSecureID } from "ente-base/id-worker";
import log from "ente-base/log";
import type { EnteFile } from "ente-media/file";
-import { fileCreationTime } from "ente-media/file-metadata";
+import { fileCreationPhotoSortTime } from "ente-media/file-metadata";
import { wait } from "ente-utils/promise";
import {
pullUserEntities,
@@ -203,8 +203,8 @@ function* enumerateFaces(faceIndices: FaceIndex[]) {
}
/**
- * Sort faces by the creation time of the file which contains them. The sorting
- * is in descending order, so the newest file is first.
+ * Sort faces by the local photo creation date of the file which contains them.
+ * The sorting is in descending order, so the newest file is first.
*
* Sorting faces temporally is meant as a heuristic for better clusters.
*/
@@ -213,25 +213,23 @@ const sortFacesNewestOnesFirst = (
localFiles: EnteFile[],
) => {
const localFileByID = new Map(localFiles.map((f) => [f.id, f]));
- const fileForFaceID = new Map(
- faces.map(({ faceID }) => [
- faceID,
- localFileByID.get(fileIDFromFaceID(faceID)!),
- ]),
- );
-
// In unexpected scenarios, we might run clustering without having the
// corresponding EnteFile available locally. This shouldn't happen, so log
// an warning, but meanwhile let the clustering proceed by assigning such
- // files an arbitrary creationTime.
- const sortTimeForFace = ({ faceID }: { faceID: string }) => {
- const file = fileForFaceID.get(faceID);
+ // files an arbitrary sort time.
+ const sortTimeByFaceID = new Map<string, number>();
+ for (const { faceID } of faces) {
+ const file = localFileByID.get(fileIDFromFaceID(faceID)!);
if (!file) {
assertionFailed(`Did not find a local file for faceID ${faceID}`);
- return 0;
+ sortTimeByFaceID.set(faceID, 0);
+ } else {
+ sortTimeByFaceID.set(faceID, fileCreationPhotoSortTime(file));
}
- return fileCreationTime(file);
- };
+ }
+
+ const sortTimeForFace = ({ faceID }: { faceID: string }) =>
+ sortTimeByFaceID.get(faceID) ?? 0;
return faces.sort((a, b) => sortTimeForFace(b) - sortTimeForFace(a));
};
diff --git a/web/packages/new/photos/services/ml/people.ts b/web/packages/new/photos/services/ml/people.ts
index 189be16169..f9680565e6 100644
--- a/web/packages/new/photos/services/ml/people.ts
+++ b/web/packages/new/photos/services/ml/people.ts
@@ -1,7 +1,7 @@
import { assertionFailed } from "ente-base/assert";
import log from "ente-base/log";
import type { EnteFile } from "ente-media/file";
-import { fileCreationTime } from "ente-media/file-metadata";
+import { fileCreationPhotoSortTime } from "ente-media/file-metadata";
import { randomSample } from "ente-utils/array";
import { computeNormalCollectionFilesFromSaved } from "../file";
import {
@@ -250,7 +250,7 @@ export const reconstructPeopleState = async (): Promise<PeopleState> => {
// file is otherwise existent.
const personFaceByID = new Map<
string,
- { faceID: string; file: EnteFile; score: number }
+ { faceID: string; file: EnteFile; score: number; sortTime: number }
>();
const faceIndexes = await savedFaceIndexes();
@@ -260,12 +260,17 @@ export const reconstructPeopleState = async (): Promise<PeopleState> => {
if (!fileID) continue;
const file = fileByID.get(fileID);
if (!file) continue;
- personFaceByID.set(faceID, { faceID, file, score });
+ personFaceByID.set(faceID, {
+ faceID,
+ file,
+ score,
+ sortTime: fileCreationPhotoSortTime(file),
+ });
}
}
// Return annotated "person faces" corresponding to the given face ids,
- // sorting them by the creation time of the file they belong to.
+ // sorting them by the local photo creation date of the file they belong to.
//
// Within the same file, sort by the face score.
const personFacesSortedNewestFirst = (faceIDs: string[]) =>
@@ -273,8 +278,8 @@ export const reconstructPeopleState = async (): Promise<PeopleState> => {
.map((faceID) => personFaceByID.get(faceID))
.filter((pf) => !!pf)
.sort((a, b) => {
- const at = fileCreationTime(a.file);
- const bt = fileCreationTime(b.file);
+ const at = a.sortTime;
+ const bt = b.sortTime;
return bt == at ? b.score - a.score : bt - at;
});