Skip to content

armgit / ente

Public Imported from GitHub
0

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

Prune

Manav Rathi3861e48737b3
diff --git a/web/packages/new/photos/services/ml/indexer.ts b/web/packages/new/photos/services/ml/indexer.ts
index 51535e6d9d..dd255f5684 100644
--- a/web/packages/new/photos/services/ml/indexer.ts
+++ b/web/packages/new/photos/services/ml/indexer.ts
@@ -16,7 +16,6 @@ import type { EnteFile } from "@/new/photos/types/file";
// import { ComlinkWorker } from "@/next/worker/comlink-worker";
import { ensure } from "@/utils/ensure";
// import type { Remote } from "comlink";
-// import type { FaceIndexerWorker } from "./indexer.worker";
/**
* Face indexing orchestrator.
@@ -130,12 +129,6 @@ class FaceIndexer {
/** The singleton instance of {@link FaceIndexer}. */
export default new FaceIndexer();
-// const createFaceIndexerComlinkWorker = () =>
-// new ComlinkWorker<typeof FaceIndexerWorker>(
-// "face-indexer",
-// new Worker(new URL("indexer.worker.ts", import.meta.url)),
-// );
-
export interface FaceIndexingStatus {
/**
* Which phase we are in within the indexing pipeline when viewed across the
diff --git a/web/packages/new/photos/services/ml/indexer.worker.ts b/web/packages/new/photos/services/ml/indexer.worker.ts
deleted file mode 100644
index b5fd600a50..0000000000
--- a/web/packages/new/photos/services/ml/indexer.worker.ts
+++ /dev/null
@@ -1,77 +0,0 @@
-import {
- closeFaceDBConnectionsIfNeeded,
- markIndexingFailed,
- saveFaceIndex,
-} from "@/new/photos/services/ml/db";
-import type { FaceIndex } from "@/new/photos/services/ml/types";
-import type { EnteFile } from "@/new/photos/types/file";
-import log from "@/next/log";
-import { fileLogID } from "../../utils/file";
-import { putFaceIndex } from "./embedding";
-import { indexFaces } from "./f-index";
-
-/**
- * Index faces in a file, save the persist the results locally, and put them on
- * remote.
- *
- * This class is instantiated in a web worker so as to not get in the way of the
- * main thread. It could've been a bunch of free standing functions too, it is
- * just a class for convenience of compatibility with how the rest of our
- * comlink workers are structured.
- */
-export class FaceIndexerWorker {
- /**
- * Index faces in a file, save the persist the results locally, and put them
- * on remote.
- *
- * @param enteFile The {@link EnteFile} to index.
- *
- * @param file If the file is one which is being uploaded from the current
- * client, then we will also have access to the file's content. In such
- * cases, pass a web {@link File} object to use that its data directly for
- * face indexing. If this is not provided, then the file's contents will be
- * downloaded and decrypted from remote.
- *
- * @param userAgent The UA of the client that is doing the indexing (us).
- */
- async index(enteFile: EnteFile, file: File | undefined, userAgent: string) {
- const f = fileLogID(enteFile);
- const startTime = Date.now();
-
- let faceIndex: FaceIndex;
- try {
- faceIndex = await indexFaces(enteFile, file, userAgent);
- } catch (e) {
- // Mark indexing as having failed only if the indexing itself
- // failed, not if there were subsequent failures (like when trying
- // to put the result to remote or save it to the local face DB).
- log.error(`Failed to index faces in ${f}`, e);
- await markIndexingFailed(enteFile.id);
- throw e;
- }
-
- try {
- await putFaceIndex(enteFile, faceIndex);
- await saveFaceIndex(faceIndex);
- } catch (e) {
- log.error(`Failed to put/save face index for ${f}`, e);
- throw e;
- }
-
- log.debug(() => {
- const nf = faceIndex.faceEmbedding.faces.length;
- const ms = Date.now() - startTime;
- return `Indexed ${nf} faces in ${f} (${ms} ms)`;
- });
-
- return faceIndex;
- }
-
- /**
- * Calls {@link closeFaceDBConnectionsIfNeeded} to close any open
- * connections to the face DB from the web worker's context.
- */
- closeFaceDB() {
- void closeFaceDBConnectionsIfNeeded();
- }
-}
diff --git a/web/packages/new/photos/services/ml/machineLearningService.ts b/web/packages/new/photos/services/ml/machineLearningService.ts
index cadd465b50..be2644c1f9 100644
--- a/web/packages/new/photos/services/ml/machineLearningService.ts
+++ b/web/packages/new/photos/services/ml/machineLearningService.ts
@@ -3,7 +3,7 @@ import log from "@/next/log";
import { CustomError, parseUploadErrorCodes } from "@ente/shared/error";
import PQueue from "p-queue";
import { syncWithLocalFilesAndGetFilesToIndex } from "./indexer";
-import { FaceIndexerWorker } from "./indexer.worker";
+import { index } from "./worker";
const batchSize = 200;
@@ -214,9 +214,7 @@ class MachineLearningService {
file: File | undefined,
userAgent: string,
) {
- const worker = new FaceIndexerWorker();
-
- await worker.index(enteFile, file, userAgent);
+ await index(enteFile, file, userAgent);
}
}