From 4e1d80380c74ffa206254de6dda1d8128b03e838 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Wed, 14 Aug 2024 13:56:19 +0530 Subject: [PATCH] pv2 --- web/apps/photos/src/services/searchService.ts | 11 +++++----- .../new/photos/services/user-entity.ts | 21 ++++++++++--------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/web/apps/photos/src/services/searchService.ts b/web/apps/photos/src/services/searchService.ts index 4ece8ab439..19719f351a 100644 --- a/web/apps/photos/src/services/searchService.ts +++ b/web/apps/photos/src/services/searchService.ts @@ -9,6 +9,7 @@ import { wipCluster, wipClusterEnable, } from "@/new/photos/services/ml"; +import { persons } 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"; @@ -27,7 +28,7 @@ import { import ComlinkSearchWorker from "utils/comlink/ComlinkSearchWorker"; import { getUniqueFiles } from "utils/file"; import { getFormattedDate } from "utils/search"; -import { getEntityKey, getLatestEntities } from "./entityService"; +import { getLatestEntities } from "./entityService"; import locationSearchService, { City } from "./locationSearchService"; const DIGITS = new Set(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]); @@ -420,12 +421,10 @@ async function getAllPeople(limit: number = undefined) { if (!(await wipClusterEnable())) return []; if (process.env.NEXT_PUBLIC_ENTE_WIP_CL_FETCH) { - const entityKey = await getEntityKey("person" as EntityType); - const peopleR = await syncPersons(entityKey.data); - const r = peopleR.length; - log.debug(() => ["people", peopleR]); + await syncPersons(); + const people = await persons(); + log.debug(() => ["people", { people }]); - if (r) return []; return []; } diff --git a/web/packages/new/photos/services/user-entity.ts b/web/packages/new/photos/services/user-entity.ts index ba04f3082a..db276a7054 100644 --- a/web/packages/new/photos/services/user-entity.ts +++ b/web/packages/new/photos/services/user-entity.ts @@ -6,6 +6,7 @@ import { apiURL } from "@/base/origins"; import { usersEncryptionKeyB64 } from "@/base/session-store"; import { nullToUndefined } from "@/utils/transform"; import { z } from "zod"; +import { gunzip } from "./gzip"; import type { Person } from "./ml/cluster-new"; import { applyPersonDiff } from "./ml/db"; @@ -16,12 +17,11 @@ import { applyPersonDiff } from "./ml/db"; * e.g. location tags, people in their photos. */ export type EntityType = - | "person" /** * The latest iteration of the Person entity format, where the data is * gzipped before encryption. */ - | "person_v2"; + "person_v2"; /** * The maximum number of items to fetch in a single diff @@ -305,14 +305,12 @@ const saveLatestUpdatedAt = (type: EntityType, value: number) => * This diff is then applied to the data we have persisted locally. */ export const syncPersons = async () => { - const type: EntityType = "person"; + const type: EntityType = "person_v2"; const entityKeyB64 = await getOrCreateEntityKeyB64(type); - const parse = ({ id, data }: UserEntity): Person => { - const rp = RemotePerson.parse( - JSON.parse(new TextDecoder().decode(data)), - ); + const parse = async (id: string, data: Uint8Array): Promise => { + const rp = RemotePerson.parse(JSON.parse(await gunzip(data))); return { id, name: rp.name, @@ -330,7 +328,11 @@ export const syncPersons = async () => { if (entities.length == 0) break; await applyPersonDiff( - entities.map((entity) => (entity.data ? parse(entity) : entity.id)), + await Promise.all( + entities.map(async ({ id, data }) => + data ? await parse(id, data) : id, + ), + ), ); sinceTime = entities.reduce( @@ -346,8 +348,7 @@ const RemotePerson = z.object({ name: z.string().nullish().transform(nullToUndefined), assigned: z.array( z.object({ - // TODO-Cluster temporary modify - id: z.number().transform((n) => n.toString()), // TODO z.string person_v2 + id: z.string(), faces: z.string().array(), }), ),