Skip to content

armgit / ente

Public Imported from GitHub
0

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

timeout

Manav Rathif8aa74979955
diff --git a/web/apps/photos/src/services/face/indexer.ts b/web/apps/photos/src/services/face/indexer.ts
index 8ac27ba1f8..a2e15cbedf 100644
--- a/web/apps/photos/src/services/face/indexer.ts
+++ b/web/apps/photos/src/services/face/indexer.ts
@@ -1,4 +1,6 @@
import type { EnteFile } from "types/file";
+import { indexFaces } from "./f-index";
+import type { MlFileData } from "./types-old";
/**
* Face indexing orchestrator.
@@ -23,17 +25,41 @@ import type { EnteFile } from "types/file";
* If nothing needs to be indexed, the indexer goes to sleep for a while.
*/
export class FaceIndexer {
- private liveItems: [file: File, enteFile: EnteFile][];
+ /** Live indexing queue. */
+ private liveItems: { file: File; enteFile: EnteFile }[];
+ /** True when we are sleeping. */
+ private isPaused = false;
+ /** Timeout for when the next time we will wake up. */
+ private wakeTimeout: ReturnType<typeof setTimeout> | undefined;
/**
* Add {@link file} associated with {@link enteFile} to the live indexing
* queue.
*/
enqueueFile(file: File, enteFile: EnteFile) {
- this.liveItems.push([file, enteFile]);
+ this.liveItems.push({ file, enteFile });
+ this.isPaused = false;
+ this.wakeUpIfNeeded()
}
- tick() {
+ private wakeUpIfNeeded() {
+ // Already awake
+ if (!this.wakeTimeout) return;
+ // Cancel the alarm, wake up now.
+ clearTimeout(this.wakeTimeout);
+ this.wakeTimeout = undefined;
+ this.tick();
+ }
+
+ private async tick() {
+ const item = this.liveItems.pop();
+ let faceIndex: MlFileData | undefined;
+ if (item) {
+ faceIndex = await indexFaces(item.enteFile, item.file);
+ } else {
+ // backfill
+ }
+ console.log("indexed face", faceIndex);
}
}