From c70c498d38fff4e64175d914f3ae1d3cdecfb3fd Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Fri, 31 May 2024 09:33:17 +0530 Subject: [PATCH] Pick from correct execution context --- web/apps/photos/src/services/face/indexer.ts | 3 +-- .../src/services/machineLearning/machineLearningService.ts | 4 ---- .../photos/src/services/machineLearning/mlWorkManager.ts | 5 +++++ 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/web/apps/photos/src/services/face/indexer.ts b/web/apps/photos/src/services/face/indexer.ts index 98eaaa02ce..893ff0c863 100644 --- a/web/apps/photos/src/services/face/indexer.ts +++ b/web/apps/photos/src/services/face/indexer.ts @@ -4,7 +4,6 @@ import { ensure } from "@/utils/ensure"; import { wait } from "@/utils/promise"; import { type Remote } from "comlink"; import { getLocalFiles } from "services/fileService"; -import machineLearningService from "services/machineLearning/machineLearningService"; import mlWorkManager from "services/machineLearning/mlWorkManager"; import type { EnteFile } from "types/file"; import { isInternalUserForML } from "utils/user"; @@ -162,7 +161,7 @@ export interface FaceIndexingStatus { } export const faceIndexingStatus = async (): Promise => { - const isSyncing = machineLearningService.isSyncing; + const isSyncing = mlWorkManager.isSyncing; const { indexedCount, indexableCount } = await indexedAndIndexableCounts(); let phase: FaceIndexingStatus["phase"]; diff --git a/web/apps/photos/src/services/machineLearning/machineLearningService.ts b/web/apps/photos/src/services/machineLearning/machineLearningService.ts index 8549ec7655..640644ada4 100644 --- a/web/apps/photos/src/services/machineLearning/machineLearningService.ts +++ b/web/apps/photos/src/services/machineLearning/machineLearningService.ts @@ -45,8 +45,6 @@ class MachineLearningService { private localSyncContext: Promise; private syncContext: Promise; - public isSyncing = false; - public async sync( token: string, userID: number, @@ -70,7 +68,6 @@ class MachineLearningService { } private async syncFiles(syncContext: MLSyncContext) { - this.isSyncing = true; try { const functions = syncContext.outOfSyncFiles.map( (outOfSyncfile) => async () => { @@ -90,7 +87,6 @@ class MachineLearningService { syncContext.error = error; } await syncContext.syncQueue.onIdle(); - this.isSyncing = false; } private async getSyncContext( diff --git a/web/apps/photos/src/services/machineLearning/mlWorkManager.ts b/web/apps/photos/src/services/machineLearning/mlWorkManager.ts index 9502c5a75d..867df8ef65 100644 --- a/web/apps/photos/src/services/machineLearning/mlWorkManager.ts +++ b/web/apps/photos/src/services/machineLearning/mlWorkManager.ts @@ -97,6 +97,8 @@ class MLWorkManager { private liveSyncWorker: ComlinkWorker; private mlSearchEnabled: boolean; + public isSyncing = false; + constructor() { this.liveSyncQueue = new PQueue({ concurrency: 1, @@ -270,6 +272,7 @@ class MLWorkManager { * things pending to process, so we should chug along at full speed. */ private async runMLSyncJob(): Promise { + this.isSyncing = true; try { // TODO: skipping is not required if we are caching chunks through service worker // currently worker chunk itself is not loaded when network is not there @@ -290,6 +293,8 @@ class MLWorkManager { // TODO: redirect/refresh to gallery in case of session_expired, stop ml sync job } catch (e) { log.error("Failed to run MLSync Job", e); + } finally { + this.isSyncing = false; } }