Skip to content

armgit / ente

Public Imported from GitHub
0

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

Propagate

Manav Rathi3f20f572d205
diff --git a/web/apps/photos/src/services/searchService.ts b/web/apps/photos/src/services/searchService.ts
index 0c203b1189..a2e6eee825 100644
--- a/web/apps/photos/src/services/searchService.ts
+++ b/web/apps/photos/src/services/searchService.ts
@@ -9,7 +9,7 @@ import {
wipCluster,
wipClusterEnable,
} from "@/new/photos/services/ml";
-import { persons } from "@/new/photos/services/ml/db";
+import { clusterGroups } from "@/new/photos/services/ml/db";
import type { SearchPerson } from "@/new/photos/services/search";
import { syncPersons } from "@/new/photos/services/user-entity";
import { EnteFile } from "@/new/photos/types/file";
@@ -425,7 +425,7 @@ async function getAllPeople(limit: number = undefined) {
done = true;
if (process.env.NEXT_PUBLIC_ENTE_WIP_CL_FETCH) {
await syncPersons();
- const people = await persons();
+ const people = await clusterGroups();
log.debug(() => ["people", { people }]);
}
diff --git a/web/packages/new/photos/services/ml/cluster-new.ts b/web/packages/new/photos/services/ml/cluster-new.ts
index 887237e66a..69e8de6f26 100644
--- a/web/packages/new/photos/services/ml/cluster-new.ts
+++ b/web/packages/new/photos/services/ml/cluster-new.ts
@@ -1,7 +1,7 @@
import { newNonSecureID } from "@/base/id-worker";
import log from "@/base/log";
import { ensure } from "@/utils/ensure";
-import { faceClusters, persons } from "./db";
+import { clusterGroups, faceClusters } from "./db";
import type { Face, FaceIndex } from "./face";
import { dotProduct } from "./math";
@@ -241,7 +241,7 @@ export const clusterFaces = async (faceIndexes: FaceIndex[]) => {
// clusters as its display face.
const faceForFaceID = new Map(faces.map((f) => [f.faceID, f]));
- const people = await persons();
+ const people = await clusterGroups();
for (const person of people) {
person.avatarFaceID = person.clusterIDs
diff --git a/web/packages/new/photos/services/ml/db.ts b/web/packages/new/photos/services/ml/db.ts
index 294203142b..53a081910c 100644
--- a/web/packages/new/photos/services/ml/db.ts
+++ b/web/packages/new/photos/services/ml/db.ts
@@ -9,26 +9,41 @@ import type { LocalFaceIndex } from "./face";
/**
* ML DB schema.
*
- * The "ML" database is made of three object stores:
+ * The "ML" database is made of the lower level "index" object stores, and
+ * higher level "cluster" object stores.
*
- * - "file-status": Contains {@link FileStatus} objects, one for each
- * {@link EnteFile} that the ML subsystem knows about. Periodically (and when
- * required), this is synced with the list of files that the current client
- * knows about locally.
+ * The index related object stores are the following:
*
- * - "face-index": Contains {@link LocalFaceIndex} objects, either indexed
- * locally or fetched from remote.
+ * - "file-status": Contains {@link FileStatus} objects, one for each
+ * {@link EnteFile} that the ML subsystem knows about. Periodically (and
+ * when required), this is synced with the list of files that the current
+ * client knows about locally.
*
- * - "clip-index": Contains {@link LocalCLIPIndex} objects, either indexed
- * locally or fetched from remote.
+ * - "face-index": Contains {@link LocalFaceIndex} objects, either indexed
+ * locally or fetched from remote.
*
- * All the stores are keyed by {@link fileID}. The "file-status" contains
+ * - "clip-index": Contains {@link LocalCLIPIndex} objects, either indexed
+ * locally or fetched from remote.
+ *
+ * These three stores are keyed by {@link fileID}. The "file-status" contains
* book-keeping about the indexing process (whether or not a file needs
* indexing, or if there were errors doing so), while the other stores contain
* the actual indexing results.
*
- * In tandem, these serve as the underlying storage for the functions exposed by
- * the ML database.
+ * In tandem, these serve as the underlying storage for the indexes maintained
+ * in the ML database.
+ *
+ * The cluster related object stores are the following:
+ *
+ * - "face-cluster": Contains {@link FaceCluster} objects, one for each
+ * cluster of faces that either the clustering algorithm produced locally or
+ * were synced from remote. It is indexed by the (cluster) ID.
+ *
+ * - "cluster-group": Contains {@link CGroup} objects, one for each group of
+ * clusters that were synced from remote. The client can also locally
+ * generate cluster groups on certain user interactions, but these too will
+ * eventually get synced with remote. This object store is indexed by the
+ * (cgroup) ID.
*/
interface MLDBSchema extends DBSchema {
"file-status": {
@@ -48,7 +63,7 @@ interface MLDBSchema extends DBSchema {
key: string;
value: FaceCluster;
};
- person: {
+ "cluster-group": {
key: string;
value: CGroup;
};
@@ -111,7 +126,7 @@ const openMLDB = async () => {
if (oldVersion < 3) {
if (process.env.NEXT_PUBLIC_ENTE_WIP_CL) {
db.createObjectStore("face-cluster", { keyPath: "id" });
- db.createObjectStore("person", { keyPath: "id" });
+ db.createObjectStore("cluster-group", { keyPath: "id" });
}
}
},
@@ -419,11 +434,11 @@ export const faceClusters = async () => {
};
/**
- * Return all person entries (aka "people") present locally.
+ * Return all cluster group entries (aka "cgroups") present locally.
*/
-export const persons = async () => {
+export const clusterGroups = async () => {
const db = await mlDB();
- return db.getAll("person");
+ return db.getAll("cluster-group");
};
/**
@@ -464,37 +479,22 @@ export const applyPersonDiff = async (diff: (string | CGroup)[]) => {
};
/**
- * Add or overwrite the entry for the given {@link person}, as identified by
+ * Add or overwrite the entry for the given {@link cgroup}, as identified by
* their {@link id}.
*/
// TODO-Cluster: Remove me
-export const savePerson = async (person: CGroup) => {
+export const saveClusterGroup = async (cgroup: CGroup) => {
const db = await mlDB();
- const tx = db.transaction("person", "readwrite");
- await Promise.all([tx.store.put(person), tx.done]);
+ const tx = db.transaction("cluster-group", "readwrite");
+ await Promise.all([tx.store.put(cgroup), tx.done]);
};
/**
- * Delete the entry for the persons with the given {@link id}, if any.
+ * Delete the entry (if any) for the cluster group with the given {@link id}.
*/
// TODO-Cluster: Remove me
-export const deletePerson = async (id: string) => {
+export const deleteClusterGroup = async (id: string) => {
const db = await mlDB();
- const tx = db.transaction("person", "readwrite");
+ const tx = db.transaction("cluster-group", "readwrite");
await Promise.all([tx.store.delete(id), tx.done]);
};
-
-/**
- * Replace the persons stored locally with the given ones.
- *
- * This function deletes all entries from the person object store, and then
- * inserts the given {@link persons} into it.
- */
-// TODO-Cluster: Remove me
-export const setPersons = async (persons: CGroup[]) => {
- const db = await mlDB();
- const tx = db.transaction("person", "readwrite");
- await tx.store.clear();
- await Promise.all(persons.map((person) => tx.store.put(person)));
- return tx.done;
-};