π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Pull out pull
Manav Rathi61b98a99646f
diff --git a/web/packages/new/photos/services/ml/worker.ts b/web/packages/new/photos/services/ml/worker.tsindex 159803a46f..14e6daee35 100644--- a/web/packages/new/photos/services/ml/worker.ts+++ b/web/packages/new/photos/services/ml/worker.ts@@ -48,24 +48,22 @@ interface IndexableItem {** ext. event state then state* ------------- --------------- --------------- * sync -> "pull" -> "idle"+ * sync -> "backfillq" -> "idle"* upload -> "liveq" -> "idle"* idleTimeout -> "backfillq" -> "idle"** where:*- * - "pull": pulling embeddings from remote- * - "liveq": indexing items that are being uploaded- * - "backfillq": indexing unindexed items otherwise- * - "idle": in between state transitions+ * - "liveq": indexing items that are being uploaded,+ * - "backfillq": fetching remote embeddings of unindexed items, and then+ * indexing them if needed,+ * - "idle": in between state transitions.*/export class MLWorker {private electron: MLWorkerElectron | undefined;private delegate: MLWorkerDelegate | undefined;private userAgent: string | undefined;- private state: "idle" | "pull" | "indexing" = "idle";- private shouldPull = false;- private havePulledAtLeastOnce = false;+ private state: "idle" | "indexing" = "idle";private liveQ: IndexableItem[] = [];private idleTimeout: ReturnType<typeof setTimeout> | undefined;private idleDuration = idleDurationStart; /* unit: seconds */@@ -74,11 +72,11 @@ export class MLWorker {* Initialize a new {@link MLWorker}.** This is conceptually the constructor, however it is easier to have this- * as a separate function to avoid confounding the comlink types too much.+ * as a separate function to avoid complicating the comlink types further.** @param electron The {@link MLWorkerElectron} that allows the worker to* use the functionality provided by our Node.js layer when running in the- * context of our desktop app+ * context of our desktop app.** @param delegate The {@link MLWorkerDelegate} the worker can use to inform* the main thread of interesting events.@@ -94,17 +92,14 @@ export class MLWorker {}/**- * Pull embeddings from remote, and start backfilling if needed.+ * Start backfilling if needed.*- * This function enqueues the pull and returns immediately without waiting- * for the pull to complete.- *- * While it only triggers a pull, once the pull is done it also checks for- * pending items to backfill. So it implicitly also triggers a backfill- * (which is why call it a less-precise sync instead of pull).+ * This function enqueues a backfill attempt and returns immediately without+ * waiting for it complete. During a backfill, it will first attempt to+ * fetch embeddings for files which don't have that data locally. If we+ * fetch and find what we need, we save it locally. Otherwise we index them.*/sync() {- this.shouldPull = true;this.wakeUp();}@@ -159,7 +154,6 @@ export class MLWorker {"ml/tick",{state: this.state,- shouldSync: this.shouldPull,liveQ: this.liveQ,idleDuration: this.idleDuration,},@@ -167,46 +161,12 @@ export class MLWorker {const scheduleTick = () => void setTimeout(() => this.tick(), 0);- // If we've been asked to sync, do that irrespective of anything else.- if (this.shouldPull) {- // Allow this flag to be reset while we're busy pulling (triggering- // another pull when we tick next).- this.shouldPull = false;- this.state = "pull";- try {- const didPull = await pull();- // Mark that we completed once attempt at pulling successfully- // (irrespective of whether or not that got us some data).- this.havePulledAtLeastOnce = true;- // Reset the idle duration if we did pull something.- if (didPull) this.idleDuration = idleDurationStart;- } catch (e) {- log.error("Failed to pull embeddings", e);- }- // Tick again, even if we got an error.- //- // While the backfillQ won't be processed until at least a pull has- // happened once (`havePulledAtLeastOnce`), the liveQ can still be- // processed since these are new files without remote embeddings.- scheduleTick();- return;- }-const liveQ = this.liveQ;this.liveQ = [];this.state = "indexing";- // Use the liveQ if present, otherwise get the next batch to backfill,- // but only if we've pulled once from remote successfully (otherwise we- // might end up reindexing files that were already indexed on remote but- // which we didn't know about since pull failed, say, for transient- // network issues).- const items =- liveQ.length > 0- ? liveQ- : this.havePulledAtLeastOnce- ? await this.backfillQ()- : [];+ // Use the liveQ if present, otherwise get the next batch to backfill.+ const items = liveQ.length > 0 ? liveQ : await this.backfillQ();const allSuccess = await indexNextBatch(items,