diff --git a/web/packages/new/photos/services/ml/db.ts b/web/packages/new/photos/services/ml/db.ts index f33271188a..be35790591 100644 --- a/web/packages/new/photos/services/ml/db.ts +++ b/web/packages/new/photos/services/ml/db.ts @@ -419,13 +419,41 @@ export const markIndexingFailed = async (fileID: number) => { */ export const faceClusters = async () => { const db = await mlDB(); - return await db.getAll("face-cluster"); + return db.getAll("face-cluster"); }; /** - * Return all people present locally. + * Return all person entries (aka "people") present locally. */ export const persons = async () => { const db = await mlDB(); - return await db.getAll("person"); + return db.getAll("person"); +}; + +/** + * 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. + */ +export const setFaceClusters = async (clusters: FaceCluster[]) => { + const db = await mlDB(); + const tx = db.transaction("face-cluster", "readwrite"); + await tx.store.clear(); + await Promise.all(clusters.map((cluster) => tx.store.put(cluster))); + return 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. + */ +export const setPersons = async (persons: Person[]) => { + 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; }; diff --git a/web/packages/new/photos/services/ml/people.ts b/web/packages/new/photos/services/ml/people.ts index 6420794e1d..d2d9c884a3 100644 --- a/web/packages/new/photos/services/ml/people.ts +++ b/web/packages/new/photos/services/ml/people.ts @@ -71,13 +71,6 @@ export const syncPeopleIndex = async () => { for (const [index, cluster] of clusters.entries()) { const faces = cluster.map((f) => allFaces[f]).filter((f) => f); - // TODO: take default display face from last leaves of hdbscan clusters - const personFace = faces.reduce((best, face) => - face.detection.probability > best.detection.probability - ? face - : best, - ); - await mlIDbStorage.putPerson(person);