Skip to content

armgit / ente

Public Imported from GitHub
0

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

Update

Manav Rathiaf680b6da3d9
diff --git a/web/packages/new/photos/services/ml/cluster.ts b/web/packages/new/photos/services/ml/cluster.ts
index acdecad3bf..51c31d2e66 100644
--- a/web/packages/new/photos/services/ml/cluster.ts
+++ b/web/packages/new/photos/services/ml/cluster.ts
@@ -3,7 +3,10 @@ import log from "@/base/log";
import { ensure } from "@/utils/ensure";
import { wait } from "@/utils/promise";
import type { EnteFile } from "../../types/file";
-import { savedCGroupUserEntities } from "../user-entity";
+import {
+ savedCGroupUserEntities,
+ updateOrCreateUserEntities,
+} from "../user-entity";
import { savedFaceClusters, saveFaceClusters } from "./db";
import {
faceDirection,
@@ -346,8 +349,14 @@ const clusterBatchLinear = async (
/**
* Use the output of the clustering phase to (a) update any remote cgroups that
* have changed, and (b) update our locally persisted clusters.
+ *
+ * @param masterKey The user's master key, required for updating the cgroups on
+ * remote if needed.
*/
-export const reconcileClusters = async (clusters: FaceCluster[]) => {
+export const reconcileClusters = async (
+ clusters: FaceCluster[],
+ masterKey: Uint8Array,
+) => {
// Index clusters by their ID for fast lookup.
const clusterByID = new Map(clusters.map((c) => [c.id, c]));
@@ -378,9 +387,14 @@ export const reconcileClusters = async (clusters: FaceCluster[]) => {
})
.filter((g) => !!g);
+ // Update remote if needed.
if (changedCGroupEntities.length) {
log.info(`Updating ${changedCGroupEntities.length} remote cgroups`);
- // TODO-Cluster do it
+ await updateOrCreateUserEntities(
+ "cgroup",
+ changedCGroupEntities,
+ masterKey,
+ );
}
// Find which clusters are part of remote cgroups.
diff --git a/web/packages/new/photos/services/ml/index.ts b/web/packages/new/photos/services/ml/index.ts
index 932c66b25d..fb58dcf30d 100644
--- a/web/packages/new/photos/services/ml/index.ts
+++ b/web/packages/new/photos/services/ml/index.ts
@@ -7,6 +7,7 @@ import { blobCache } from "@/base/blob-cache";
import { ensureElectron } from "@/base/electron";
import { isDevBuild } from "@/base/env";
import log from "@/base/log";
+import { masterKeyFromSession } from "@/base/session-store";
import type { Electron } from "@/base/types/ipc";
import { ComlinkWorker } from "@/base/worker/comlink-worker";
import { FileType } from "@/media/file-type";
@@ -18,14 +19,10 @@ import { isInternalUser } from "../feature-flags";
import { getRemoteFlag, updateRemoteFlag } from "../remote-store";
import { setSearchPeople } from "../search";
import type { UploadItem } from "../upload/types";
+import { pullUserEntities } from "../user-entity";
import { regenerateFaceCrops } from "./crop";
import { clearMLDB, getFaceIndex, getIndexableAndIndexedCounts } from "./db";
-import {
- pullCGroups,
- reconstructPeople,
- type NamedPerson,
- type Person,
-} from "./people";
+import { reconstructPeople, type NamedPerson, type Person } from "./people";
import { MLWorker } from "./worker";
import type { CLIPMatches } from "./worker-types";
@@ -317,13 +314,15 @@ export const mlSync = async () => {
// Fetch indexes, or index locally if needed.
await w.index();
- // Fetch existing cgroups from remote.
- await pullCGroups();
-
- // Generate or update local clusters.
// TODO-Cluster
if (await wipClusterEnable()) {
- await w.clusterFaces();
+ const masterKey = await masterKeyFromSession();
+
+ // Fetch existing cgroups from remote.
+ await pullUserEntities("cgroup", masterKey);
+
+ // Generate or update local clusters.
+ await w.clusterFaces(masterKey);
}
await updatePeople();
diff --git a/web/packages/new/photos/services/ml/people.ts b/web/packages/new/photos/services/ml/people.ts
index 7c1d0fb3b4..cc8a5a145b 100644
--- a/web/packages/new/photos/services/ml/people.ts
+++ b/web/packages/new/photos/services/ml/people.ts
@@ -1,8 +1,7 @@
-import { masterKeyFromSession } from "@/base/session-store";
import { wipClusterEnable } from ".";
import type { EnteFile } from "../../types/file";
import { getLocalFiles } from "../files";
-import { pullUserEntities, savedCGroupUserEntities } from "../user-entity";
+import { savedCGroupUserEntities } from "../user-entity";
import type { FaceCluster } from "./cluster";
import { getFaceIndexes, savedFaceClusters } from "./db";
import { fileIDFromFaceID } from "./face";
@@ -123,16 +122,6 @@ export interface Person {
displayFaceFile: EnteFile;
}
-/**
- * Fetch existing cgroups for the user from remote and save them to DB.
- */
-export const pullCGroups = async () => {
- if (!(await wipClusterEnable())) return;
-
- const masterKey = await masterKeyFromSession();
- await pullUserEntities("cgroup", masterKey);
-};
-
export type NamedPerson = Omit<Person, "name"> & {
name: string;
};
diff --git a/web/packages/new/photos/services/ml/worker.ts b/web/packages/new/photos/services/ml/worker.ts
index d745abb520..b9156e4106 100644
--- a/web/packages/new/photos/services/ml/worker.ts
+++ b/web/packages/new/photos/services/ml/worker.ts
@@ -298,14 +298,17 @@ export class MLWorker {
* with remote) is complete so that we cluster the latest set of faces, and
* after we have fetched the latest cgroups from remote (so that we do no
* overwrite any remote updates).
+ *
+ * @param masterKey The user's master key, required for updating remote
+ * cgroups if needed.
*/
- async clusterFaces() {
+ async clusterFaces(masterKey: Uint8Array) {
const clusters = await clusterFaces(
await getFaceIndexes(),
await getAllLocalFiles(),
(progress) => this.updateClusteringProgress(progress),
);
- await reconcileClusters(clusters);
+ await reconcileClusters(clusters, masterKey);
this.updateClusteringProgress(undefined);
}