π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Essence
Manav Rathi512766ebedf9
diff --git a/web/apps/photos/src/services/machineLearning/mlWorkManager.ts b/web/apps/photos/src/services/machineLearning/mlWorkManager.tsindex 1cb61af00e..d1421ac6bd 100644--- a/web/apps/photos/src/services/machineLearning/mlWorkManager.ts+++ b/web/apps/photos/src/services/machineLearning/mlWorkManager.ts@@ -8,25 +8,19 @@ import PQueue from "p-queue";import { createFaceComlinkWorker } from "services/face";import mlIDbStorage from "services/face/db";import type { DedicatedMLWorker } from "services/face/face.worker";-import { MLSyncResult } from "services/face/types";import { EnteFile } from "types/file";import { logQueueStats } from "./machineLearningService";export type JobState = "Scheduled" | "Running" | "NotScheduled";-export interface MLSyncJobResult {- shouldBackoff: boolean;- mlSyncResult: MLSyncResult;-}-export class MLSyncJob {- private runCallback: () => Promise<MLSyncJobResult>;+ private runCallback: () => Promise<boolean>;private state: JobState;private stopped: boolean;private intervalSec: number;private nextTimeoutId: ReturnType<typeof setTimeout>;- constructor(runCallback: () => Promise<MLSyncJobResult>) {+ constructor(runCallback: () => Promise<boolean>) {this.runCallback = runCallback;this.state = "NotScheduled";this.stopped = true;@@ -65,13 +59,11 @@ export class MLSyncJob {this.state = "Running";try {- const jobResult = await this.runCallback();- if (jobResult && jobResult.shouldBackoff) {- this.intervalSec = Math.min(960, this.intervalSec * 2);- } else {+ if (await this.runCallback()) {this.resetInterval();+ } else {+ this.intervalSec = Math.min(960, this.intervalSec * 2);}- log.info("Job completed");} catch (e) {console.error("Error while running Job: ", e);} finally {@@ -255,7 +247,14 @@ class MLWorkManager {this.syncJobWorker = undefined;}- private async runMLSyncJob(): Promise<MLSyncJobResult> {+ /**+ * Returns `false` to indicate that either an error occurred, or there are+ * not more files to process, or that we cannot currently process files.+ *+ * Which means that when it returns true, all is well and there are more+ * things pending to process, so we should chug along at full speed.+ */+ private async runMLSyncJob(): Promise<boolean> {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@@ -263,10 +262,7 @@ class MLWorkManager {log.info("Skipping ml-sync job run as not connected to internet.",);- return {- shouldBackoff: true,- mlSyncResult: undefined,- };+ return false;}const token = getToken();@@ -276,16 +272,9 @@ class MLWorkManager {const mlSyncResult = await jobWorkerProxy.sync(token, userID);// this.terminateSyncJobWorker();- const jobResult: MLSyncJobResult = {- shouldBackoff:- !!mlSyncResult.error || mlSyncResult.nOutOfSyncFiles < 1,- mlSyncResult,- };- log.info("ML Sync Job result: ", JSON.stringify(jobResult));+ return !mlSyncResult.error && mlSyncResult.nOutOfSyncFiles > 0;// TODO: redirect/refresh to gallery in case of session_expired, stop ml sync job-- return jobResult;} catch (e) {log.error("Failed to run MLSync Job", e);}