Skip to content

armgit / ente

Public Imported from GitHub
0

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

Impl details

Manav Rathid62ca44675d8
diff --git a/web/apps/photos/src/services/sync.ts b/web/apps/photos/src/services/sync.ts
index 1c3a9b9d95..82a0f59d1d 100644
--- a/web/apps/photos/src/services/sync.ts
+++ b/web/apps/photos/src/services/sync.ts
@@ -1,12 +1,6 @@
import { triggerFeatureFlagsFetchIfNeeded } from "@/new/photos/services/feature-flags";
-import {
- isMLSupported,
- mlStatusSync,
- mlSync,
- wipClusterEnable,
-} from "@/new/photos/services/ml";
-import { syncCGroups } from "@/new/photos/services/ml/cgroups";
-import { rereadCGroups, searchDataSync } from "@/new/photos/services/search";
+import { isMLSupported, mlStatusSync, mlSync } from "@/new/photos/services/ml";
+import { searchDataSync } from "@/new/photos/services/search";
import { syncMapEnabled } from "services/userService";
/**
@@ -37,12 +31,4 @@ export const preFileInfoSync = async () => {
* before doing the file sync and thus should run immediately after login.
*/
export const sync = () =>
- Promise.all([
- syncMapEnabled(),
- process.env.NEXT_PUBLIC_ENTE_WIP_CL &&
- wipClusterEnable().then((enable) =>
- enable ? syncCGroups().then(rereadCGroups) : undefined,
- ),
- isMLSupported && mlSync(),
- searchDataSync(),
- ]);
+ Promise.all([syncMapEnabled(), mlSync(), searchDataSync()]);
diff --git a/web/packages/new/photos/services/ml/cgroups.ts b/web/packages/new/photos/services/ml/cgroups.ts
index 77cdd0ee8f..23715eb3b9 100644
--- a/web/packages/new/photos/services/ml/cgroups.ts
+++ b/web/packages/new/photos/services/ml/cgroups.ts
@@ -1,5 +1,7 @@
import { masterKeyFromSession } from "@/base/session-store";
+import { setCGroups } from "../search";
import { pullCGroups } from "../user-entity";
+import { clusterGroups } from "./db";
/**
* A cgroup ("cluster group") is a group of clusters (possibly containing a
@@ -146,4 +148,12 @@ export const syncCGroups = async () => {
* implement the sync without needing to make an blocking API request for every
* user interaction.
*/
+
+ // Re-read the cgroups across which we should search from the local ML DB.
+ //
+ // This DB read can happen in the search worker too, but that would cause
+ // another handle to the DB to be opened (from the search worker's context).
+ // Making the DB call here avoids that (not that we noticed any issues, but
+ // preemptively trying not to poke IndexedDB too much lest it be flaky).
+ await setCGroups(await clusterGroups());
};
diff --git a/web/packages/new/photos/services/ml/index.ts b/web/packages/new/photos/services/ml/index.ts
index 1da7869136..a4862b158a 100644
--- a/web/packages/new/photos/services/ml/index.ts
+++ b/web/packages/new/photos/services/ml/index.ts
@@ -18,6 +18,7 @@ import { proxy, transfer } from "comlink";
import { isInternalUser } from "../feature-flags";
import { getRemoteFlag, updateRemoteFlag } from "../remote-store";
import type { UploadItem } from "../upload/types";
+import { syncCGroups } from "./cgroups";
import {
type ClusterFace,
type ClusteringOpts,
@@ -288,19 +289,30 @@ export const mlStatusSync = async () => {
};
/**
- * Perform a ML sync.
+ * Perform a ML sync, whatever is applicable.
*
* This is called during the global sync sequence, after files information have
* been synced with remote.
*
* If ML is enabled, it pulls any missing embeddings from remote and starts
- * indexing to backfill any missing values.
+ * indexing to backfill any missing values. It also syncs cgroups and updates
+ * the search service to use the latest values.
*
* This will only have an effect if {@link mlStatusSync} has been called at
* least once prior to calling this in the sync sequence.
*/
export const mlSync = async () => {
- if (_state.isMLEnabled) await worker().then((w) => w.sync());
+ if (_state.isMLEnabled) {
+ await Promise.all([
+ // On-device ML, if supported.
+ isMLSupported && worker().then((w) => w.sync()),
+ // "People".
+ process.env.NEXT_PUBLIC_ENTE_WIP_CL &&
+ wipClusterEnable().then((enable) =>
+ enable ? syncCGroups() : undefined,
+ ),
+ ]);
+ }
};
/**
diff --git a/web/packages/new/photos/services/search/index.ts b/web/packages/new/photos/services/search/index.ts
index 220bc50e64..df7f67fe30 100644
--- a/web/packages/new/photos/services/search/index.ts
+++ b/web/packages/new/photos/services/search/index.ts
@@ -4,7 +4,7 @@ import { ComlinkWorker } from "@/base/worker/comlink-worker";
import { FileType } from "@/media/file-type";
import i18n, { t } from "i18next";
import { clipMatches, isMLEnabled, isMLSupported } from "../ml";
-import { clusterGroups } from "../ml/db";
+import type { CGroup } from "../ml/cgroups";
import type {
LabelledFileType,
LabelledSearchDateComponents,
@@ -59,16 +59,10 @@ export const setSearchableCollectionsAndFiles = (
) => void worker().then((w) => w.setSearchableCollectionsAndFiles(data));
/**
- * Re-read the cgroups across which we should search from the local ML DB.
+ * Set the cgroups that we should search across.
*/
-export const rereadCGroups = async () => {
- const w = await worker();
- // This DB read can happen in the search worker too, but that would cause
- // another handle to the DB to be opened (from the search worker's context).
- // Make the DB call here to avoid that (not that we noticed any issues, but
- // preemptively trying not to poke IndexedDB too much lest it be flaky).
- return w.setCGroups(await clusterGroups());
-};
+export const setCGroups = (data: CGroup[]) =>
+ worker().then((w) => w.setCGroups(data));
/**
* Convert a search string into (annotated) suggestions that can be shown in the