This commit is contained in:
Manav Rathi
2024-08-16 15:19:43 +05:30
parent 3f20f572d2
commit 2ae98148ae
2 changed files with 11 additions and 11 deletions

View File

@@ -444,8 +444,8 @@ export const clusterGroups = async () => {
/**
* Replace the face clusters stored locally with the given ones.
*
* This function deletes all entries from the person object store, and then
* inserts the given {@link clusters} into it.
* This function deletes all entries from the face cluster object store, and
* then inserts the given {@link clusters} into it.
*/
export const setFaceClusters = async (clusters: FaceCluster[]) => {
const db = await mlDB();
@@ -456,19 +456,19 @@ export const setFaceClusters = async (clusters: FaceCluster[]) => {
};
/**
* Update the person store to reflect the given changes, in order.
* Update the cluster group store to reflect the given changes.
*
* @param diff A list of changes to apply. Each entry is either
*
* - A string, in which case the person with the given string as their ID
* should be deleted from the store, or
* - A string, in which case the cluster group with the given string as their
* ID should be deleted from the store, or
*
* - A person, in which case it should add or overwrite the entry for the
* corresponding person (as identified by their {@link id}).
* - A cgroup, in which case it should add or overwrite the entry for the
* corresponding cluster group (as identified by its {@link id}).
*/
export const applyPersonDiff = async (diff: (string | CGroup)[]) => {
export const applyCGroupDiff = async (diff: (string | CGroup)[]) => {
const db = await mlDB();
const tx = db.transaction("person", "readwrite");
const tx = db.transaction("cluster-group", "readwrite");
// See: [Note: Diff response will have at most one entry for an id]
await Promise.all(
diff.map((d) =>

View File

@@ -8,7 +8,7 @@ import { nullToUndefined } from "@/utils/transform";
import { z } from "zod";
import { gunzip } from "./gzip";
import type { CGroup } from "./ml/cluster-new";
import { applyPersonDiff } from "./ml/db";
import { applyCGroupDiff } from "./ml/db";
/**
* User entities are predefined lists of otherwise arbitrary data that the user
@@ -344,7 +344,7 @@ export const syncPersons = async () => {
const entities = await userEntityDiff(type, sinceTime, entityKeyB64);
if (entities.length == 0) break;
await applyPersonDiff(
await applyCGroupDiff(
await Promise.all(
entities.map(async ({ id, data }) =>
data ? await parse(id, data) : id,