Skip to content

armgit / ente

Public Imported from GitHub
0

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

Sequence

Manav Rathi2722b50cc04b
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index 216789f9b9..9a16723da2 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -14,7 +14,6 @@ import {
getLocalFiles,
getLocalTrashedFiles,
} from "@/new/photos/services/files";
-import { wipClusterLocalOnce } from "@/new/photos/services/ml";
import type { Person } from "@/new/photos/services/ml/cgroups";
import {
filterSearchableFiles,
@@ -681,8 +680,6 @@ export default function Gallery() {
};
}, [selectAll, clearSelection]);
- useEffect(() => wipClusterLocalOnce(), []);
-
const fileToCollectionsMap = useMemoSingleThreaded(() => {
return constructFileToCollectionMap(files);
}, [files]);
diff --git a/web/apps/photos/src/services/sync.ts b/web/apps/photos/src/services/sync.ts
index 82a0f59d1d..012af2fe11 100644
--- a/web/apps/photos/src/services/sync.ts
+++ b/web/apps/photos/src/services/sync.ts
@@ -30,5 +30,9 @@ export const preFileInfoSync = async () => {
* libraries after initial login), and the `preFileInfoSync`, which is called
* before doing the file sync and thus should run immediately after login.
*/
-export const sync = () =>
- Promise.all([syncMapEnabled(), mlSync(), searchDataSync()]);
+export const sync = async () => {
+ await Promise.all([syncMapEnabled(), searchDataSync()]);
+ // ML sync might take a very long time for initial indexing, so don't wait
+ // for it to finish.
+ void mlSync();
+};
diff --git a/web/packages/new/photos/services/ml/cgroups.ts b/web/packages/new/photos/services/ml/cgroups.ts
index e7316e11f6..5966b9ca4c 100644
--- a/web/packages/new/photos/services/ml/cgroups.ts
+++ b/web/packages/new/photos/services/ml/cgroups.ts
@@ -144,7 +144,7 @@ export const syncCGroups = async () => {
* @return A list of {@link Person}s, sorted by the number of files that they
* reference.
*/
-export const updatedPeople = async () => {
+export const peopleFromCGroups = async () => {
if (!process.env.NEXT_PUBLIC_ENTE_WIP_CL) return [];
if (!(await wipClusterEnable())) return [];
diff --git a/web/packages/new/photos/services/ml/index.ts b/web/packages/new/photos/services/ml/index.ts
index df70bbe30d..1bed3f27ce 100644
--- a/web/packages/new/photos/services/ml/index.ts
+++ b/web/packages/new/photos/services/ml/index.ts
@@ -18,7 +18,7 @@ import { isInternalUser } from "../feature-flags";
import { getRemoteFlag, updateRemoteFlag } from "../remote-store";
import { setSearchPeople } from "../search";
import type { UploadItem } from "../upload/types";
-import { syncCGroups, updatedPeople, type Person } from "./cgroups";
+import { peopleFromCGroups, syncCGroups, type Person } from "./cgroups";
import { regenerateFaceCrops } from "./crop";
import { clearMLDB, getFaceIndex, getIndexableAndIndexedCounts } from "./db";
import { MLWorker } from "./worker";
@@ -51,6 +51,11 @@ class MLState {
*/
comlinkWorker: Promise<ComlinkWorker<typeof MLWorker>> | undefined;
+ /**
+ * `true` if a sync is currently in progress.
+ */
+ isSyncing = false;
+
/**
* Subscriptions to {@link MLStatus} updates.
*
@@ -227,6 +232,7 @@ export const disableML = async () => {
await updateIsMLEnabledRemote(false);
setIsMLEnabledLocal(false);
_state.isMLEnabled = false;
+ _state.isSyncing = false;
await terminateMLWorker();
triggerStatusUpdate();
};
@@ -308,11 +314,36 @@ export const mlStatusSync = async () => {
* least once prior to calling this in the sync sequence.
*/
export const mlSync = async () => {
- if (_state.isMLEnabled) {
- await Promise.all([worker().then((w) => w.sync()), syncCGroups()]).then(
- updatePeople,
- );
- }
+ if (!_state.isMLEnabled) return;
+ if (_state.isSyncing) return;
+ _state.isSyncing = true;
+
+ // Dependency order for the sync
+ //
+ // files -> faces -> cgroups -> clusters
+ //
+
+ // Fetch indexes, or index locally if needed.
+ await worker().then((w) => w.sync());
+
+ // Fetch existing cgroups.
+ await syncCGroups();
+
+ // Generate local clusters
+ // TODO-Cluster
+ // Warning - this is heavily WIP
+ wipClusterLocalOnce();
+
+ // Update our in-memory snapshot of people.
+ const namedPeople = await peopleFromCGroups();
+ _state.peopleRemote = namedPeople;
+ updatePeopleSnapshot();
+
+ // Notify the search subsystem of the update. Since the search only used
+ // named cgroups, we only give it the people we got from cgroups.
+ setSearchPeople(namedPeople);
+
+ _state.isSyncing = false;
};
/**
@@ -559,17 +590,6 @@ const setPeopleSnapshot = (snapshot: Person[] | undefined) => {
_state.peopleListeners.forEach((l) => l());
};
-/**
- * Update our in-memory snapshot of people, also notifying the search subsystem
- * of the update.
- */
-const updatePeople = async () => {
- const people = await updatedPeople();
- _state.peopleRemote = people;
- updatePeopleSnapshot();
- setSearchPeople(people);
-};
-
/**
* Use CLIP to perform a natural language search over image embeddings.
*