Skip to content

armgit / ente

Public Imported from GitHub
0

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

Fix circular dependency warning

Manav Rathi1360378aaac2
diff --git a/web/apps/photos/src/pages/_app.tsx b/web/apps/photos/src/pages/_app.tsx
index 5731b292a9..f71e503a27 100644
--- a/web/apps/photos/src/pages/_app.tsx
+++ b/web/apps/photos/src/pages/_app.tsx
@@ -55,7 +55,7 @@ import {
setIsFaceIndexingEnabled,
} from "services/face/indexer";
import { photosLogout } from "services/logout";
-import mlWorkManager from "services/machineLearning/mlWorkManager";
+import mlWorkManager from "services/face/mlWorkManager";
import {
getFamilyPortalRedirectURL,
getRoadmapRedirectURL,
diff --git a/web/apps/photos/src/services/face/index.ts b/web/apps/photos/src/services/face/index.ts
index 86fa9ab20b..e69de29bb2 100644
--- a/web/apps/photos/src/services/face/index.ts
+++ b/web/apps/photos/src/services/face/index.ts
@@ -1,8 +0,0 @@
-import { ComlinkWorker } from "@/next/worker/comlink-worker";
-import type { DedicatedMLWorker } from "services/face/face.worker";
-
-const createFaceWebWorker = () =>
- new Worker(new URL("face.worker.ts", import.meta.url));
-
-export const createFaceComlinkWorker = (name: string) =>
- new ComlinkWorker<typeof DedicatedMLWorker>(name, createFaceWebWorker());
diff --git a/web/apps/photos/src/services/face/indexer.ts b/web/apps/photos/src/services/face/indexer.ts
index 8c4eeb0cf7..1ab0a6b9aa 100644
--- a/web/apps/photos/src/services/face/indexer.ts
+++ b/web/apps/photos/src/services/face/indexer.ts
@@ -1,10 +1,8 @@
import { ComlinkWorker } from "@/next/worker/comlink-worker";
import { ensure } from "@/utils/ensure";
-import { wait } from "@/utils/promise";
-import { type Remote } from "comlink";
+import type { Remote } from "comlink";
import { isBetaUser, isInternalUser } from "services/feature-flag";
import { getAllLocalFiles } from "services/fileService";
-import mlWorkManager from "services/machineLearning/mlWorkManager";
import type { EnteFile } from "types/file";
import { isInternalUserForML } from "utils/user";
import {
@@ -13,7 +11,7 @@ import {
indexedAndIndexableCounts,
syncWithLocalFiles,
} from "./db";
-import { type FaceIndexerWorker } from "./indexer.worker";
+import type { FaceIndexerWorker } from "./indexer.worker";
/**
* Face indexing orchestrator.
@@ -41,33 +39,33 @@ class FaceIndexer {
/** Timeout for when the next time we will wake up. */
private wakeTimeout: ReturnType<typeof setTimeout> | undefined;
- /**
- * Add a file to the live indexing queue.
- *
- * @param enteFile An {@link EnteFile} that should be indexed.
- *
- * @param file The contents of {@link enteFile} as a web {@link File}
- * object, if available.
- */
- enqueueFile(enteFile: EnteFile, file: File | undefined) {
- // If face indexing is not enabled, don't enqueue anything. Later on if
- // the user turns on face indexing these files will get indexed as part
- // of the backfilling anyway, the live indexing is just an optimization.
- if (!mlWorkManager.isMlSearchEnabled) return;
-
- this.liveItems.push({ enteFile, file });
- this.wakeUpIfNeeded();
- }
-
- private wakeUpIfNeeded() {
- // Already awake.
- if (!this.wakeTimeout) return;
- // Cancel the alarm, wake up now.
- clearTimeout(this.wakeTimeout);
- this.wakeTimeout = undefined;
- // Get to work.
- this.tick();
- }
+ // /**
+ // * Add a file to the live indexing queue.
+ // *
+ // * @param enteFile An {@link EnteFile} that should be indexed.
+ // *
+ // * @param file The contents of {@link enteFile} as a web {@link File}
+ // * object, if available.
+ // */
+ // enqueueFile(enteFile: EnteFile, file: File | undefined) {
+ // // If face indexing is not enabled, don't enqueue anything. Later on if
+ // // the user turns on face indexing these files will get indexed as part
+ // // of the backfilling anyway, the live indexing is just an optimization.
+ // if (!mlWorkManager.isMlSearchEnabled) return;
+
+ // this.liveItems.push({ enteFile, file });
+ // this.wakeUpIfNeeded();
+ // }
+
+ // private wakeUpIfNeeded() {
+ // // Already awake.
+ // if (!this.wakeTimeout) return;
+ // // Cancel the alarm, wake up now.
+ // clearTimeout(this.wakeTimeout);
+ // this.wakeTimeout = undefined;
+ // // Get to work.
+ // this.tick();
+ // }
/* TODO-ML(MR): This code is not currently in use */
@@ -85,34 +83,34 @@ class FaceIndexer {
faceIndexer = (): Promise<Remote<FaceIndexerWorker>> =>
(this._faceIndexer ??= createFaceIndexerComlinkWorker().remote);
- private async tick() {
- console.log("tick");
-
- const item = this.liveItems.pop();
- if (!item) {
- // TODO-ML: backfill instead if needed here.
- this.wakeTimeout = setTimeout(() => {
- this.wakeTimeout = undefined;
- this.wakeUpIfNeeded();
- }, 30 * 1000);
- return;
- }
- /*
- const fileID = item.enteFile.id;
- try {
- const faceIndex = await indexFaces(item.enteFile, item.file, userAgent);
- log.info(`faces in file ${fileID}`, faceIndex);
- } catch (e) {
- log.error(`Failed to index faces in file ${fileID}`, e);
- markIndexingFailed(item.enteFile.id);
- }
-*/
- // Let the runloop drain.
- await wait(0);
- // Run again.
- // TODO
- // this.tick();
- }
+ // private async tick() {
+ // console.log("tick");
+
+ // const item = this.liveItems.pop();
+ // if (!item) {
+ // // TODO-ML: backfill instead if needed here.
+ // this.wakeTimeout = setTimeout(() => {
+ // this.wakeTimeout = undefined;
+ // this.wakeUpIfNeeded();
+ // }, 30 * 1000);
+ // return;
+ // }
+ // /*
+ // const fileID = item.enteFile.id;
+ // try {
+ // const faceIndex = await indexFaces(item.enteFile, item.file, userAgent);
+ // log.info(`faces in file ${fileID}`, faceIndex);
+ // } catch (e) {
+ // log.error(`Failed to index faces in file ${fileID}`, e);
+ // markIndexingFailed(item.enteFile.id);
+ // }
+ // */
+ // // Let the runloop drain.
+ // await wait(0);
+ // // Run again.
+ // // TODO
+ // // this.tick();
+ // }
/**
* Add a newly uploaded file to the face indexing queue.
@@ -162,8 +160,9 @@ export interface FaceIndexingStatus {
nTotalFiles: number;
}
-export const faceIndexingStatus = async (): Promise<FaceIndexingStatus> => {
- const isSyncing = mlWorkManager.isSyncing;
+export const faceIndexingStatus = async (
+ isSyncing: boolean,
+): Promise<FaceIndexingStatus> => {
const { indexedCount, indexableCount } = await indexedAndIndexableCounts();
let phase: FaceIndexingStatus["phase"];
diff --git a/web/apps/photos/src/services/machineLearning/mlWorkManager.ts b/web/apps/photos/src/services/face/mlWorkManager.ts
similarity index 97%
rename from web/apps/photos/src/services/machineLearning/mlWorkManager.ts
rename to web/apps/photos/src/services/face/mlWorkManager.ts
index 867df8ef65..3e25864bae 100644
--- a/web/apps/photos/src/services/machineLearning/mlWorkManager.ts
+++ b/web/apps/photos/src/services/face/mlWorkManager.ts
@@ -7,12 +7,17 @@ import { eventBus, Events } from "@ente/shared/events";
import { getToken, getUserID } from "@ente/shared/storage/localStorage/helpers";
import debounce from "debounce";
import PQueue from "p-queue";
-import { createFaceComlinkWorker } from "services/face";
import type { DedicatedMLWorker } from "services/face/face.worker";
import { EnteFile } from "types/file";
export type JobState = "Scheduled" | "Running" | "NotScheduled";
+const createFaceWebWorker = () =>
+ new Worker(new URL("face.worker.ts", import.meta.url));
+
+const createFaceComlinkWorker = (name: string) =>
+ new ComlinkWorker<typeof DedicatedMLWorker>(name, createFaceWebWorker());
+
export class MLSyncJob {
private runCallback: () => Promise<boolean>;
private state: JobState;
diff --git a/web/apps/photos/src/services/logout.ts b/web/apps/photos/src/services/logout.ts
index 9da892bad2..bad5259016 100644
--- a/web/apps/photos/src/services/logout.ts
+++ b/web/apps/photos/src/services/logout.ts
@@ -5,7 +5,7 @@ import DownloadManager from "./download";
import exportService from "./export";
import { clearFaceData } from "./face/db";
import { clearFeatureFlagSessionState } from "./feature-flag";
-import mlWorkManager from "./machineLearning/mlWorkManager";
+import mlWorkManager from "./face/mlWorkManager";
/**
* Logout sequence for the photos app.
diff --git a/web/apps/photos/src/services/searchService.ts b/web/apps/photos/src/services/searchService.ts
index edc3899892..27786a2d3a 100644
--- a/web/apps/photos/src/services/searchService.ts
+++ b/web/apps/photos/src/services/searchService.ts
@@ -21,6 +21,7 @@ import { clipService, computeClipMatchScore } from "./clip-service";
import { localCLIPEmbeddings } from "./embeddingService";
import { getLatestEntities } from "./entityService";
import { faceIndexingStatus, isFaceIndexingEnabled } from "./face/indexer";
+import mlWorkManager from "./face/mlWorkManager";
import locationSearchService, { City } from "./locationSearchService";
const DIGITS = new Set(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]);
@@ -178,7 +179,8 @@ export async function getAllPeopleSuggestion(): Promise<Array<Suggestion>> {
export async function getIndexStatusSuggestion(): Promise<Suggestion> {
try {
- const indexStatus = await faceIndexingStatus();
+ const isSyncing = mlWorkManager.isSyncing;
+ const indexStatus = await faceIndexingStatus(isSyncing);
let label: string;
switch (indexStatus.phase) {