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);