π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Wait for indexing to complete before clustering
Manav Rathi48cab57d5319
diff --git a/web/packages/new/photos/services/ml/index.ts b/web/packages/new/photos/services/ml/index.tsindex 93587683dc..18fd8e53cd 100644--- a/web/packages/new/photos/services/ml/index.ts+++ b/web/packages/new/photos/services/ml/index.ts@@ -315,7 +315,7 @@ export const mlSync = async () => {//// Fetch indexes, or index locally if needed.- await worker().then((w) => w.sync());+ await worker().then((w) => w.index());// Fetch existing cgroups from remote.await pullCGroups();diff --git a/web/packages/new/photos/services/ml/worker.ts b/web/packages/new/photos/services/ml/worker.tsindex 37713e33b3..5c20e9e7f7 100644--- a/web/packages/new/photos/services/ml/worker.ts+++ b/web/packages/new/photos/services/ml/worker.ts@@ -109,6 +109,7 @@ export class MLWorker {private liveQ: IndexableItem[] = [];private idleTimeout: ReturnType<typeof setTimeout> | undefined;private idleDuration = idleDurationStart; /* unit: seconds */+ private onNextIdles: (() => void)[] = [];/*** Initialize a new {@link MLWorker}.@@ -133,17 +134,19 @@ export class MLWorker {}/**- * Start backfilling if needed.- *- * This function enqueues a backfill attempt and returns immediately without- * waiting for it complete.+ * Start backfilling if needed, and return after there are no more items+ * remaining to backfill.** During a backfill, we first attempt to fetch ML data for files which* don't have that data locally. If on fetching we find what we need, we* save it locally. Otherwise we index them.*/- sync() {+ index() {+ const nextIdle = new Promise<void>((resolve) =>+ this.onNextIdles.push(resolve),+ );this.wakeUp();+ return nextIdle;}/** Invoked in response to external events. */@@ -249,6 +252,11 @@ export class MLWorker {this.idleDuration = Math.min(this.idleDuration * 2, idleDurationMax);this.idleTimeout = setTimeout(scheduleTick, this.idleDuration * 1000);this.delegate?.workerDidUpdateStatus();++ // Resolve any awaiting promises returned from `index`.+ const onNextIdles = this.onNextIdles;+ this.onNextIdles = [];+ onNextIdles.forEach((f) => f());}/** Return the next batch of items to backfill (if any). */