From fd1f3c6710b60dc4f3ea4accf29cdc53474bfde0 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Wed, 14 Aug 2024 13:51:43 +0530 Subject: [PATCH] Sync 1 --- web/packages/new/photos/services/user-entity.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/web/packages/new/photos/services/user-entity.ts b/web/packages/new/photos/services/user-entity.ts index 8aa12b1810..ba04f3082a 100644 --- a/web/packages/new/photos/services/user-entity.ts +++ b/web/packages/new/photos/services/user-entity.ts @@ -168,7 +168,7 @@ export const userEntityDiff = async ( * * See also, [Note: User entity keys]. */ -const entityKey = async (type: EntityType) => { +const getOrCreateEntityKeyB64 = async (type: EntityType) => { const encryptionKeyB64 = await usersEncryptionKeyB64(); const worker = await sharedCryptoWorker(); @@ -304,9 +304,11 @@ const saveLatestUpdatedAt = (type: EntityType, value: number) => * * This diff is then applied to the data we have persisted locally. */ -export const syncPersons = async (entityKeyB64: string) => { +export const syncPersons = async () => { const type: EntityType = "person"; + const entityKeyB64 = await getOrCreateEntityKeyB64(type); + const parse = ({ id, data }: UserEntity): Person => { const rp = RemotePerson.parse( JSON.parse(new TextDecoder().decode(data)), @@ -327,10 +329,12 @@ export const syncPersons = async (entityKeyB64: string) => { const entities = await userEntityDiff(type, sinceTime, entityKeyB64); if (entities.length == 0) break; - await applyPersonDiff(entities.map((e) => (e.data ? parse(e) : e.id))); + await applyPersonDiff( + entities.map((entity) => (entity.data ? parse(entity) : entity.id)), + ); sinceTime = entities.reduce( - (max, e) => Math.max(max, e.updatedAt), + (max, entity) => Math.max(max, entity.updatedAt), sinceTime, ); await saveLatestUpdatedAt(type, sinceTime);