π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
chore(app):added-logs-to-source-cluster-refrehsing
Aswin Asoke9b9e093ae0e
diff --git a/web/apps/photos/src/components/Collections/CollectionMapDialog.tsx b/web/apps/photos/src/components/Collections/CollectionMapDialog.tsxindex edf573f2eb..0325aba626 100644--- a/web/apps/photos/src/components/Collections/CollectionMapDialog.tsx+++ b/web/apps/photos/src/components/Collections/CollectionMapDialog.tsx@@ -1587,7 +1587,9 @@ export const CollectionMapDialog: React.FC<CollectionMapDialogProps> = ({const handleRemotePull = useCallback(() =>- onRemotePull ? onRemotePull({ silent: true }) : Promise.resolve(),+ onRemotePull+ ? onRemotePull({ silent: true, source: "map-dialog" })+ : Promise.resolve(),[onRemotePull],);const visualFeedback = useMemo(() => onVisualFeedback, [onVisualFeedback]);diff --git a/web/apps/photos/src/components/FileListWithViewer.tsx b/web/apps/photos/src/components/FileListWithViewer.tsxindex 4d61ccdf64..e61208430c 100644--- a/web/apps/photos/src/components/FileListWithViewer.tsx+++ b/web/apps/photos/src/components/FileListWithViewer.tsx@@ -16,6 +16,7 @@ import { downloadAndSaveFiles } from "ente-gallery/services/save";import type { Collection } from "ente-media/collection";import type { EnteFile } from "ente-media/file";import { fileCreationPhotoDate, fileFileName } from "ente-media/file-metadata";+import type { RemotePullOpts } from "ente-new/photos/components/gallery";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";@@ -65,7 +66,7 @@ export type FileListWithViewerProps = {* Called when an action in the file viewer requires us to perform a full* pull from remote.*/- onRemotePull: () => Promise<void>;+ onRemotePull: (opts?: RemotePullOpts) => Promise<void>;activeCollectionSummary?: CollectionSummary;activeCollection?: Collection;/**@@ -265,7 +266,7 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({);const handleTriggerRemotePull = useCallback(- () => void onRemotePull(),+ () => void onRemotePull({ source: "file-viewer-action" }),[onRemotePull],);diff --git a/web/apps/photos/src/components/Upload.tsx b/web/apps/photos/src/components/Upload.tsxindex 2af32f82da..9e606159bf 100644--- a/web/apps/photos/src/components/Upload.tsx+++ b/web/apps/photos/src/components/Upload.tsx@@ -401,7 +401,10 @@ export const Upload: React.FC<UploadProps> = ({setDesktopFilePaths(filePaths);};- watcher.init(upload, () => void onRemotePull());+ watcher.init(+ upload,+ () => void onRemotePull({ source: "watcher-upload" }),+ );electron.pendingUploads().then((pending) => {if (!pending) return;@@ -878,12 +881,12 @@ export const Upload: React.FC<UploadProps> = ({) => {uploadManager.prepareForNewUpload(parsedMetadataJSONMap);uploadManager.showUploadProgressDialog();- await onRemotePull({ silent: true });+ await onRemotePull({ silent: true, source: "pre-upload" });};function postUploadAction() {resetUploadUIState();- void onRemotePull();+ void onRemotePull({ source: "post-upload" });}const uploadFiles = async (diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsxindex 00ae86bbbf..500b268d75 100644--- a/web/apps/photos/src/pages/gallery.tsx+++ b/web/apps/photos/src/pages/gallery.tsx@@ -600,7 +600,7 @@ const Page: React.FC = () => {}// Fetch data from remote (this will include the newly joined album if any)- await remotePull();+ await remotePull({ source: "gallery-mount" });// Navigate directly to the joined albumif (joinedAlbumId) {@@ -615,13 +615,13 @@ const Page: React.FC = () => {// Start the interval that does a periodic pull.syncIntervalID = setInterval(- () => remotePull({ silent: true }),+ () => remotePull({ silent: true, source: "gallery-periodic" }),5 * 60 * 1000 /* 5 minutes */,);if (electron) {unsubscribeMainWindowFocus = subscribeMainWindowFocus(() => {- remotePull({ silent: true });+ remotePull({ silent: true, source: "desktop-focus" });void watcher.checkAccessibility();});if (await shouldShowWhatsNew(electron)) showWhatsNew();@@ -896,7 +896,7 @@ const Page: React.FC = () => {const remotePull = useCallback(async (opts?: RemotePullOpts) =>remotePullQueue.current.add(async () => {- const { silent } = opts ?? {};+ const { silent, source } = opts ?? {};// Pre-flight checks.if (!navigator.onLine) return;@@ -915,7 +915,7 @@ const Page: React.FC = () => {if (!silent) showLoadingBar();await prePullFiles();await remoteFilesPull();- await postPullFiles();+ await postPullFiles(source);} catch (e) {log.error("Remote pull failed", e);} finally {@@ -964,7 +964,10 @@ const Page: React.FC = () => {);notifyOthersFiles = processedCount != selectedFiles.length;clearSelection();- await remotePull({ silent: true });+ await remotePull({+ silent: true,+ source: "remove-from-collection",+ });} catch (e) {onGenericError(e);} finally {@@ -1006,7 +1009,10 @@ const Page: React.FC = () => {showMiniDialog(notifyOthersFilesDialogAttributes());}clearSelection();- await remotePull({ silent: true });+ await remotePull({+ silent: true,+ source: `collection-op:${op}`,+ });} finally {hideLoadingBar();}@@ -1072,7 +1078,10 @@ const Page: React.FC = () => {pendingSingleFileAdd.current.sourceCollectionSummaryID,);- await remotePull({ silent: true });+ await remotePull({+ silent: true,+ source: "single-file-add-new-album",+ });// Show custom toast with album name and navigationsetAddToAlbumProgress({open: true,@@ -1216,7 +1225,10 @@ const Page: React.FC = () => {setPublicLinkToast({ open: true, url: resolvedURL });clearSelection();- await remotePull({ silent: true });+ await remotePull({+ silent: true,+ source: "selected-files-quick-link",+ });return;}@@ -1235,7 +1247,10 @@ const Page: React.FC = () => {await handleFavoriteFileOp(op, selectedFiles);clearSelection();if (processed) {- await remotePull({ silent: true });+ await remotePull({+ silent: true,+ source: `file-op:${op}`,+ });}if (skippedUnsupportedSharedFile) {showMiniDialog(@@ -1280,7 +1295,7 @@ const Page: React.FC = () => {showMiniDialog(notifyOthersFilesDialogAttributes());}clearSelection();- await remotePull({ silent: true });+ await remotePull({ silent: true, source: `file-op:${op}` });} catch (e) {onGenericError(e);} finally {@@ -1351,7 +1366,7 @@ const Page: React.FC = () => {location.longitude,);}- void remotePull({ silent: true });+ void remotePull({ silent: true, source: "edit-location" });},[selectedFilesInView, user, remotePull],);@@ -1560,7 +1575,7 @@ const Page: React.FC = () => {customDomain,);setPublicLinkToast({ open: true, url: resolvedURL });- await remotePull({ silent: true });+ await remotePull({ silent: true, source: "viewer-send-link" });} catch (e) {onGenericError(e);} finally {@@ -1627,7 +1642,10 @@ const Page: React.FC = () => {showLoadingBar();try {await updateCollectionCover(activeCollection, coverID);- await remotePull({ silent: true });+ await remotePull({+ silent: true,+ source: "update-collection-cover",+ });return true;} catch (e) {onGenericError(e);@@ -1887,7 +1905,10 @@ const Page: React.FC = () => {[file],sourceCollectionSummaryID,);- await remotePull({ silent: true });+ await remotePull({+ silent: true,+ source: "single-file-add-to-album",+ });// Show custom toast with album name and navigationsetAddToAlbumProgress({open: true,diff --git a/web/packages/new/photos/components/gallery/index.tsx b/web/packages/new/photos/components/gallery/index.tsxindex 22f2de3b43..809315dbaf 100644--- a/web/packages/new/photos/components/gallery/index.tsx+++ b/web/packages/new/photos/components/gallery/index.tsx@@ -47,6 +47,10 @@ export interface RemotePullOpts {* Default: `false`.*/silent?: boolean;+ /**+ * The action that triggered this pull. Used to annotate downstream logs.+ */+ source?: string;}/*** The context in which a selection was made.diff --git a/web/packages/new/photos/services/ml/cluster.ts b/web/packages/new/photos/services/ml/cluster.tsindex ebd5b0b516..e24d22cf7e 100644--- a/web/packages/new/photos/services/ml/cluster.ts+++ b/web/packages/new/photos/services/ml/cluster.ts@@ -43,6 +43,20 @@ export interface ClusteringProgress {total: number;}+export type ClusterFacesReason =+ | "add-cgroup"+ | "add-cluster-to-cgroup"+ | "apply-person-suggestion-updates"+ | "delete-cgroup"+ | "enable-ml"+ | "ignore-cluster"+ | "live-upload-index"+ | "ml-sync"+ | "remote-pull"+ | `remote-pull:${string}`+ | "rename-cgroup"+ | "set-cgroup-pinned";+/** A {@link Face} annotated with data needed during clustering. */export type ClusterFace = Omit<Face, "embedding"> & {embedding: Float32Array;@@ -70,6 +84,7 @@ export const _clusterFaces = async (faceIndexes: FaceIndex[],localFiles: EnteFile[],onProgress: (progress: ClusteringProgress) => void,+ reason: ClusterFacesReason,) => {const startTime = Date.now();@@ -175,7 +190,9 @@ export const _clusterFaces = async (}const t = `(${Date.now() - startTime} ms)`;- log.info(`Refreshed ${clusters.length} clusters from ${total} faces ${t}`);+ log.info(+ `Refreshed ${clusters.length} clusters from ${total} faces ${t} [reason=${reason}]`,+ );return { clusters, modifiedClusterIDs };};diff --git a/web/packages/new/photos/services/ml/index.ts b/web/packages/new/photos/services/ml/index.tsindex d5c23bf421..e866a6dc50 100644--- a/web/packages/new/photos/services/ml/index.ts+++ b/web/packages/new/photos/services/ml/index.ts@@ -26,7 +26,7 @@ import {type CGroup,} from "../user-entity";import { deleteUserEntity } from "../user-entity/remote";-import type { FaceCluster } from "./cluster";+import type { ClusterFacesReason, FaceCluster } from "./cluster";import { regenerateFaceCrops } from "./crop";import {clearMLDB,@@ -232,7 +232,7 @@ export const enableML = async () => {setInterimScheduledStatus();resetPeopleStateSnapshot();// Trigger updates, but don't wait for them to finish.- void updateMLStatusSnapshot().then(mlSync);+ void updateMLStatusSnapshot().then(() => mlSync("enable-ml"));};/**@@ -349,7 +349,7 @@ export const pullMLStatus = async () => {* This will only have an effect if {@link pullMLStatus} has been called at* least once prior to calling this in the pull sequence.*/-export const mlSync = async () => {+export const mlSync = async (reason: ClusterFacesReason = "ml-sync") => {if (!_state.isMLEnabled) return;if (_state.isSyncing) return;_state.isSyncing = true;@@ -369,19 +369,19 @@ export const mlSync = async () => {// Fetch indexes, or index locally if needed.await worker().then((w) => w.index());- await updateClustersAndPeople();+ await updateClustersAndPeople(reason);_state.isSyncing = false;};-const updateClustersAndPeople = async () => {+const updateClustersAndPeople = async (reason: ClusterFacesReason) => {const masterKey = await ensureMasterKeyFromSession();// Fetch existing cgroups from remote.await pullUserEntities("cgroup", masterKey);// Generate or update local clusters.- await (await worker()).clusterFaces(masterKey);+ await (await worker()).clusterFaces(masterKey, reason);// Update the people shown in the UI.await updatePeopleState();@@ -407,7 +407,8 @@ const debounceUpdateClustersAndPeople = pDebounce(30 * 1e3,);-const workerDidUnawaitedIndex = () => void debounceUpdateClustersAndPeople();+const workerDidUnawaitedIndex = () =>+ void debounceUpdateClustersAndPeople("live-upload-index");/*** Run indexing on a file which was uploaded from this client.@@ -789,7 +790,7 @@ export const addCGroup = async (name: string, cluster: FaceCluster) => {},await ensureMasterKeyFromSession(),);- await mlSync();+ await mlSync("add-cgroup");return id;};@@ -820,7 +821,7 @@ export const addClusterToCGroup = async ([{ ...cgroup, data: { ...cgroup.data, assigned, rejectedFaceIDs } }],await ensureMasterKeyFromSession(),);- return mlSync();+ return mlSync("add-cluster-to-cgroup");};/**@@ -837,7 +838,7 @@ export const renameCGroup = async (cgroup: CGroup, name: string) => {[{ ...cgroup, data: { ...cgroup.data, name } }],await ensureMasterKeyFromSession(),);- return mlSync();+ return mlSync("rename-cgroup");};/**@@ -847,7 +848,7 @@ export const renameCGroup = async (cgroup: CGroup, name: string) => {*/export const deleteCGroup = async ({ id }: CGroup) => {await deleteUserEntity(id);- return mlSync();+ return mlSync("delete-cgroup");};/**@@ -859,7 +860,7 @@ export const setCGroupPinned = async (cgroup: CGroup, isPinned: boolean) => {[{ ...cgroup, data: { ...cgroup.data, isPinned } }],await ensureMasterKeyFromSession(),);- return mlSync();+ return mlSync("set-cgroup-pinned");};export const pinCGroup = async (cgroup: CGroup) =>@@ -978,7 +979,7 @@ export const applyPersonSuggestionUpdates = async (updates,await ensureMasterKeyFromSession(),);- return mlSync();+ return mlSync("apply-person-suggestion-updates");};/**@@ -1001,5 +1002,5 @@ export const ignoreCluster = async (cluster: FaceCluster) => {},await ensureMasterKeyFromSession(),);- return mlSync();+ return mlSync("ignore-cluster");};diff --git a/web/packages/new/photos/services/ml/worker.ts b/web/packages/new/photos/services/ml/worker.tsindex c7999c9b8a..9f38fd5937 100644--- a/web/packages/new/photos/services/ml/worker.ts+++ b/web/packages/new/photos/services/ml/worker.ts@@ -26,6 +26,7 @@ import {import {_clusterFaces,reconcileClusters,+ type ClusterFacesReason,type ClusteringProgress,} from "./cluster";import { saveFaceCrops } from "./crop";@@ -321,11 +322,12 @@ export class MLWorker {* @param masterKey The user's master key (as a base64 string), required for* updating remote cgroups if needed.*/- async clusterFaces(masterKey: string) {+ async clusterFaces(masterKey: string, reason: ClusterFacesReason) {const { clusters, modifiedClusterIDs } = await _clusterFaces(await savedFaceIndexes(),await savedCollectionFiles(),(progress) => this.updateClusteringProgress(progress),+ reason,);await reconcileClusters(clusters, modifiedClusterIDs, masterKey);this.updateClusteringProgress(undefined);diff --git a/web/packages/new/photos/services/pull.ts b/web/packages/new/photos/services/pull.tsindex 70af879058..69e85d1bbc 100644--- a/web/packages/new/photos/services/pull.ts+++ b/web/packages/new/photos/services/pull.ts@@ -139,9 +139,9 @@ export const pullFiles = async (opts?: PullFilesOpts) => {** See: [Note: Remote pull]*/-export const postPullFiles = async () => {+export const postPullFiles = async (source?: string) => {await Promise.all([searchDataSync(), videoProcessingSyncIfNeeded()]);// ML sync might take a very long time for initial indexing, so don't wait// for it to finish.- void mlSync();+ void mlSync(source ? `remote-pull:${source}` : "remote-pull");};