Skip to content

armgit / ente

Public Imported from GitHub
0

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

Nomenclature

Manav Rathi34211dafef96
diff --git a/web/packages/new/photos/services/ml/cgroups.ts b/web/packages/new/photos/services/ml/cgroups.ts
index 49388eb990..5a2d24957c 100644
--- a/web/packages/new/photos/services/ml/cgroups.ts
+++ b/web/packages/new/photos/services/ml/cgroups.ts
@@ -1,3 +1,6 @@
+import { masterKeyFromSession } from "@/base/session-store";
+import { pullCGroups } from "../user-entity";
+
/**
* A cgroup ("cluster group") is a group of clusters (possibly containing a
* single cluster) that the user has interacted with.
@@ -109,7 +112,7 @@ export interface CGroup {
* - They can hide a cluster. This creates an unnamed cgroup so that the
* user's other clients know not to show it.
*/
-export const syncCGroups = () => {
+export const syncCGroups = async () => {
// 1. Fetch existing cgroups for the user from remote.
// 2. Save them to DB.
// 3. Prune stale faceIDs from the clusters in the DB.
@@ -118,7 +121,10 @@ export const syncCGroups = () => {
//
// The user can see both the cgroups and clusters in the UI, but only the
// cgroups are synced.
- // const syncCGroupsWithRemote()
+
+ const masterKey = await masterKeyFromSession();
+ await pullCGroups(masterKey);
+
/*
* After clustering, we also do some routine cleanup. Faces belonging to files
* that have been deleted (including those in Trash) should be pruned off.
diff --git a/web/packages/new/photos/services/search/worker.ts b/web/packages/new/photos/services/search/worker.ts
index 714453b419..0492863db0 100644
--- a/web/packages/new/photos/services/search/worker.ts
+++ b/web/packages/new/photos/services/search/worker.ts
@@ -9,8 +9,8 @@ import * as chrono from "chrono-node";
import { expose } from "comlink";
import { z } from "zod";
import {
+ pullLocationTags,
savedLocationTags,
- syncLocationTags,
type LocationTag,
} from "../user-entity";
import type {
@@ -54,7 +54,7 @@ export class SearchWorker {
*/
async sync(masterKey: Uint8Array) {
return Promise.all([
- syncLocationTags(masterKey)
+ pullLocationTags(masterKey)
.then(() => savedLocationTags())
.then((ts) => {
this.locationTags = ts.map((t) => ({
diff --git a/web/packages/new/photos/services/user-entity.ts b/web/packages/new/photos/services/user-entity.ts
index 7064d21d82..5c12ddaebb 100644
--- a/web/packages/new/photos/services/user-entity.ts
+++ b/web/packages/new/photos/services/user-entity.ts
@@ -35,16 +35,16 @@ export type EntityType =
| "cgroup";
/**
- * Sync our local location tags with those on remote.
+ * Update our local location tags with changes from remote.
*
* This function fetches all the location tag user entities from remote and
- * updates our local database. It uses local state to remember the last time it
- * synced, so each subsequent sync is a lightweight diff.
+ * updates our local database. It uses local state to remember the latest entry
+ * the last time it did a pull, so each subsequent pull is a lightweight diff.
*
* @param masterKey The user's master key. This is used to encrypt and decrypt
* the location tags specific entity key.
*/
-export const syncLocationTags = async (masterKey: Uint8Array) => {
+export const pullLocationTags = async (masterKey: Uint8Array) => {
const decoder = new TextDecoder();
const parse = (id: string, data: Uint8Array): LocationTag => ({
id,
@@ -63,7 +63,7 @@ export const syncLocationTags = async (masterKey: Uint8Array) => {
return saveLocationTags([...existingTagsByID.values()]);
};
- return syncUserEntity("location", masterKey, processBatch);
+ return pullUserEntities("location", masterKey, processBatch);
};
/** Zod schema for the tag that we get from or put to remote. */
@@ -89,7 +89,7 @@ const saveLocationTags = (tags: LocationTag[]) =>
/**
* Return all the location tags that are present locally.
*
- * Use {@link syncLocationTags} to sync this list with remote.
+ * Use {@link pullLocationTags} to synchronize this list with remote.
*/
export const savedLocationTags = async () =>
LocalLocationTag.array().parse(
@@ -97,7 +97,7 @@ export const savedLocationTags = async () =>
);
/**
- * Sync the {@link CGroup} entities that we have locally with remote.
+ * Update our local cgroups with changes from remote.
*
* This fetches all the user entities corresponding to the "cgroup" entity type
* from remote that have been created, updated or deleted since the last time we
@@ -108,7 +108,7 @@ export const savedLocationTags = async () =>
* @param masterKey The user's master key. This is used to encrypt and decrypt
* the cgroup specific entity key.
*/
-export const syncCGroups = (masterKey: Uint8Array) => {
+export const pullCGroups = (masterKey: Uint8Array) => {
const parse = async (id: string, data: Uint8Array): Promise<CGroup> => {
const rp = RemoteCGroup.parse(JSON.parse(await gunzip(data)));
return {
@@ -130,7 +130,7 @@ export const syncCGroups = (masterKey: Uint8Array) => {
),
);
- return syncUserEntity("cgroup", masterKey, processBatch);
+ return pullUserEntities("cgroup", masterKey, processBatch);
};
const RemoteCGroup = z.object({
@@ -209,7 +209,7 @@ interface UserEntityChange {
* The user's {@link masterKey} is used to decrypt (or encrypt, when generating
* a new one) the entity key.
*/
-const syncUserEntity = async (
+const pullUserEntities = async (
type: EntityType,
masterKey: Uint8Array,
processBatch: (entities: UserEntityChange[]) => Promise<void>,