Skip to content

armgit / ente

Public Imported from GitHub
0

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

OnnA

Manav Rathid6344093b6e5
diff --git a/web/packages/new/photos/services/ml/cgroups.ts b/web/packages/new/photos/services/ml/cgroups.ts
index 5a2d24957c..77cdd0ee8f 100644
--- a/web/packages/new/photos/services/ml/cgroups.ts
+++ b/web/packages/new/photos/services/ml/cgroups.ts
@@ -21,11 +21,14 @@ import { pullCGroups } from "../user-entity";
* cluster, or they may hide an named {@link CGroup}. In both cases, we promote
* the cluster to a CGroup if needed so that their request to hide gets synced.
*
+ * cgroups are synced with remote.
+ *
* While in our local representation we separately maintain clusters and link to
* them from within CGroups by their clusterID, in the remote representation
- * clusters themselves don't get synced. Instead, the "cgroup" entities synced
- * with remote contain the clusters within themselves. So a group that gets
- * synced with remote looks something like:
+ * clusters themselves don't get synced. Instead, the cgroup entities synced
+ * with remote contain the clusters within themselves.
+ *
+ * That is, a cgroup that gets synced with remote looks something like:
*
* { id, name, clusters: [{ clusterID, faceIDs }] }
*
@@ -66,7 +69,7 @@ export interface CGroup {
isHidden: boolean;
/**
* The ID of the face that should be used as the cover photo for this
- * cluster group (if the user has set one).
+ * cluster group. Optional.
*
* This is similar to the [@link displayFaceID}, the difference being:
*
@@ -76,6 +79,13 @@ export interface CGroup {
* into effect if the user has not explicitly selected a face.
*/
avatarFaceID: string | undefined;
+}
+
+/**
+ * A {@link CGroup} annotated with various in-memory state to make it easier for
+ * the upper layers of our code to directly use it.
+ */
+export type AnnotatedCGroup = CGroup & {
/**
* Locally determined ID of the "best" face that should be used as the
* display face, to represent this cluster group in the UI.
@@ -84,7 +94,7 @@ export interface CGroup {
* {@link avatarFaceID}.
*/
displayFaceID: string | undefined;
-}
+};
/**
* Syncronize the user's cluster groups with remote, running local clustering if
diff --git a/web/packages/new/photos/services/ml/db.ts b/web/packages/new/photos/services/ml/db.ts
index 86cc0afd03..833bcffbd3 100644
--- a/web/packages/new/photos/services/ml/db.ts
+++ b/web/packages/new/photos/services/ml/db.ts
@@ -32,17 +32,17 @@ import type { LocalFaceIndex } from "./face";
* In tandem, these serve as the underlying storage for the indexes maintained
* in the ML database.
*
- * The cluster related object stores are the following:
+ * The face clustering 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.
+ * 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.
+ * cgroup ID.
*/
interface MLDBSchema extends DBSchema {
"file-status": {
@@ -441,24 +441,3 @@ export const applyCGroupDiff = async (diff: (string | CGroup)[]) => {
);
return tx.done;
};
-
-/**
- * Add or overwrite the entry for the given {@link cgroup}, as identified by
- * their {@link id}.
- */
-// TODO-Cluster: Remove me
-export const saveClusterGroup = async (cgroup: CGroup) => {
- const db = await mlDB();
- const tx = db.transaction("cluster-group", "readwrite");
- await Promise.all([tx.store.put(cgroup), tx.done]);
-};
-
-/**
- * Delete the entry (if any) for the cluster group with the given {@link id}.
- */
-// TODO-Cluster: Remove me
-export const deleteClusterGroup = async (id: string) => {
- const db = await mlDB();
- const tx = db.transaction("cluster-group", "readwrite");
- await Promise.all([tx.store.delete(id), tx.done]);
-};
diff --git a/web/packages/new/photos/services/user-entity.ts b/web/packages/new/photos/services/user-entity.ts
index 5c12ddaebb..731a39d565 100644
--- a/web/packages/new/photos/services/user-entity.ts
+++ b/web/packages/new/photos/services/user-entity.ts
@@ -110,14 +110,13 @@ export const savedLocationTags = async () =>
*/
export const pullCGroups = (masterKey: Uint8Array) => {
const parse = async (id: string, data: Uint8Array): Promise<CGroup> => {
- const rp = RemoteCGroup.parse(JSON.parse(await gunzip(data)));
+ const r = RemoteCGroup.parse(JSON.parse(await gunzip(data)));
return {
id,
- name: rp.name,
- clusterIDs: rp.assigned.map(({ id }) => id),
- isHidden: rp.isHidden,
- avatarFaceID: rp.avatarFaceID,
- displayFaceID: undefined,
+ name: r.name,
+ clusterIDs: r.assigned.map(({ id }) => id),
+ isHidden: r.isHidden,
+ avatarFaceID: r.avatarFaceID,
};
};
@@ -141,6 +140,8 @@ const RemoteCGroup = z.object({
faces: z.string().array(),
}),
),
+ // The remote cgroup also has a "rejected" property, but that is not
+ // currently used by any of the clients.
isHidden: z.boolean(),
avatarFaceID: z.string().nullish().transform(nullToUndefined),
});