Skip to content

armgit / ente

Public Imported from GitHub
0

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

Notify about live uploads

Manav Rathi4d4b3f8bef90
diff --git a/web/packages/new/photos/services/ml/index.ts b/web/packages/new/photos/services/ml/index.ts
index ddb88dd69c..f7cc7a9a17 100644
--- a/web/packages/new/photos/services/ml/index.ts
+++ b/web/packages/new/photos/services/ml/index.ts
@@ -107,7 +107,7 @@ const worker = () =>
const createComlinkWorker = async () => {
const electron = ensureElectron();
- const delegate = { workerDidUpdateStatus };
+ const delegate = { workerDidUpdateStatus, workerDidUnawaitedIndex };
// Obtain a message port from the Electron layer.
const messagePort = await createMLWorker(electron);
@@ -313,14 +313,20 @@ export const mlSync = async () => {
// Dependency order for the sync
//
- // files -> faces -> cgroups -> clusters
+ // files -> faces -> cgroups -> clusters -> people
//
- const w = await worker();
-
// Fetch indexes, or index locally if needed.
- await w.index();
+ await (await worker()).index();
+
+ await updateClustersAndPeople();
+
+ _state.isSyncing = false;
+};
+
+const workerDidUnawaitedIndex = () => void updateClustersAndPeople();
+const updateClustersAndPeople = async () => {
// TODO-Cluster
if (await wipClusterEnable()) {
const masterKey = await masterKeyFromSession();
@@ -329,12 +335,9 @@ export const mlSync = async () => {
await pullUserEntities("cgroup", masterKey);
// Generate or update local clusters.
- await w.clusterFaces(masterKey);
+ await (await worker()).clusterFaces(masterKey);
}
-
await updatePeople();
-
- _state.isSyncing = false;
};
/**
diff --git a/web/packages/new/photos/services/ml/worker-types.ts b/web/packages/new/photos/services/ml/worker-types.ts
index b12598d52b..16153b3b2b 100644
--- a/web/packages/new/photos/services/ml/worker-types.ts
+++ b/web/packages/new/photos/services/ml/worker-types.ts
@@ -13,6 +13,19 @@ export interface MLWorkerDelegate {
* indicating the indexing or clustering status to be updated.
*/
workerDidUpdateStatus: () => void;
+ /**
+ * Called when the worker indexes some files, but then notices that the main
+ * thread was not awaiting the indexing (e.g. it was not initiated by the
+ * main thread during a sync, but happened because of a live upload).
+ *
+ * In such cases, it uses this method to inform the main thread that some
+ * files were indexed, so that it can update any dependent state (e.g.
+ * clusters).
+ *
+ * It doesn't always call this because otherwise the main thread would need
+ * some extra code to avoid updating the dependent state twice.
+ */
+ workerDidUnawaitedIndex: () => void;
}
/**
diff --git a/web/packages/new/photos/services/ml/worker.ts b/web/packages/new/photos/services/ml/worker.ts
index ce460d3610..42ee2a439f 100644
--- a/web/packages/new/photos/services/ml/worker.ts
+++ b/web/packages/new/photos/services/ml/worker.ts
@@ -274,6 +274,12 @@ export class MLWorker {
this.onNextIdles = [];
this.countSinceLastIdle = 0;
onNextIdles.forEach((f) => f(countSinceLastIdle));
+
+ // If no one was waiting, then let the main thread know via a different
+ // channel so that it can update the clusters and people.
+ if (onNextIdles.length == 0 && countSinceLastIdle > 0) {
+ this.delegate?.workerDidUnawaitedIndex();
+ }
}
/** Return the next batch of items to backfill (if any). */