π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Fetching state
Manav Rathifed7864b11ae
diff --git a/web/apps/photos/src/services/searchService.ts b/web/apps/photos/src/services/searchService.tsindex 987a4cdacb..1be9fa01fd 100644--- a/web/apps/photos/src/services/searchService.ts+++ b/web/apps/photos/src/services/searchService.ts@@ -193,6 +193,10 @@ export async function getMLStatusSuggestion(): Promise<Suggestion> {case "indexing":label = t("indexing_photos", status);break;+ case "fetching":+ // label = pt("Fetching"indexing_photos", status);+ label = `Fetching indexes (${status.nSyncedFiles} / ${status.nTotalFiles})`;+ break;case "clustering":label = t("indexing_people", status);break;diff --git a/web/packages/new/photos/components/MLSettings.tsx b/web/packages/new/photos/components/MLSettings.tsxindex 581869e0bd..87613912d7 100644--- a/web/packages/new/photos/components/MLSettings.tsx+++ b/web/packages/new/photos/components/MLSettings.tsx@@ -1,6 +1,7 @@import { EnteDrawer } from "@/base/components/EnteDrawer";import { MenuItemGroup } from "@/base/components/Menu";import { Titlebar } from "@/base/components/Titlebar";+import { pt } from "@/base/i18n";import log from "@/base/log";import {disableML,@@ -299,12 +300,15 @@ const ManageML: React.FC<ManageMLProps> = ({let status: string;switch (phase) {- case "indexing":- status = "running";- break;case "scheduled":status = "scheduled";break;+ case "fetching":+ status = "fetching";+ break;+ case "indexing":+ status = "running";+ break;// TODO: Clusteringdefault:status = "done";@@ -352,7 +356,9 @@ const ManageML: React.FC<ManageMLProps> = ({{t("indexing")}</Typography><Typography>- {t("indexing_status", { context: status })}+ {status == "fetching"+ ? pt("Fetching")+ : t("indexing_status", { context: status })}</Typography></Stack><Divider sx={{ marginInlineStart: 2 }} />diff --git a/web/packages/new/photos/services/ml/index.ts b/web/packages/new/photos/services/ml/index.tsindex f6e0be04e6..e4c56a4569 100644--- a/web/packages/new/photos/services/ml/index.ts+++ b/web/packages/new/photos/services/ml/index.ts@@ -404,13 +404,16 @@ export type MLStatus =** - "indexing": The indexer is currently running.*+ * - "fetching": The indexer is currently running, but we're primarily+ * fetching indexes for existing files.+ ** - "clustering": All file we know of have been indexed, and we are now* clustering the faces that were found.** - "done": ML indexing and face clustering is complete for the user's* library.*/- phase: "scheduled" | "indexing" | "clustering" | "done";+ phase: "scheduled" | "indexing" | "fetching" | "clustering" | "done";/** The number of files that have already been indexed. */nSyncedFiles: number;/** The total number of files that are eligible for indexing. */@@ -478,8 +481,9 @@ const getMLStatus = async (): Promise<MLStatus> => {let phase: MLStatus["phase"];if (indexableCount > 0) {- const isIndexing = await (await worker()).isIndexing();- phase = !isIndexing ? "scheduled" : "indexing";+ const state = await (await worker()).state;+ phase =+ state == "indexing" || state == "fetching" ? state : "scheduled";} else {phase = "done";}diff --git a/web/packages/new/photos/services/ml/worker.ts b/web/packages/new/photos/services/ml/worker.tsindex 7e6825ad9b..79520cc076 100644--- a/web/packages/new/photos/services/ml/worker.ts+++ b/web/packages/new/photos/services/ml/worker.ts@@ -1,4 +1,5 @@import { clientPackageName } from "@/base/app";+import { assertionFailed } from "@/base/assert";import { isHTTP4xxError } from "@/base/http";import { getKVN } from "@/base/kv";import { ensureAuthToken } from "@/base/local-user";@@ -39,6 +40,20 @@ import {} from "./ml-data";import type { CLIPMatches, MLWorkerDelegate } from "./worker-types";+/**+ * A rough hint at what the worker is up to.+ *+ * - "idle": Not doing anything+ * - "tick": Transitioning to a new state+ * - "indexing": Indexing+ * - "fetching": A subset of indexing+ *+ * During indexing, the state is set to "fetching" whenever remote provided us+ * data for more than 50% of the files that we requested from it in the last+ * fetch during indexing.+ */+export type WorkerState = "idle" | "tick" | "indexing" | "fetching";+const idleDurationStart = 5; /* 5 seconds */const idleDurationMax = 16 * 60; /* 16 minutes */@@ -76,9 +91,11 @@ interface IndexableItem {* particular, for finding the closest CLIP match when the user does a search.*/export class MLWorker {+ /** The last known state of the worker. */+ public state: WorkerState = "idle";+private electron: ElectronMLWorker | undefined;private delegate: MLWorkerDelegate | undefined;- private state: "idle" | "tick" | "indexing" = "idle";private liveQ: IndexableItem[] = [];private idleTimeout: ReturnType<typeof setTimeout> | undefined;private idleDuration = idleDurationStart; /* unit: seconds */@@ -164,13 +181,6 @@ export class MLWorker {}}- /**- * Return true if we're currently indexing.- */- isIndexing() {- return this.state == "indexing";- }-/*** Find {@link CLIPMatches} for a given {@link searchPhrase}.*/@@ -234,8 +244,20 @@ export class MLWorker {200,);if (!filesByID.size) return [];+// Fetch their existing ML data (if any).const mlDataByID = await fetchMLData(filesByID);++ // If the number of files for which remote gave us data is more than 50%+ // of what we asked of it, assume we are "fetching", not "indexing".+ // This is a heuristic to try and show a better indexing state in the UI+ // (so that the user does not think that their files are being+ // unnecessarily reindexed).+ if (this.state != "indexing" && this.state != "fetching")+ assertionFailed(`Unexpected state ${this.state}`);+ this.state =+ mlDataByID.size * 2 > filesByID.size ? "fetching" : "indexing";+// Return files after annotating them with their existing ML data.return Array.from(filesByID, ([id, file]) => ({enteFile: file,