From 864a240d0b6b431aeb9d14cdb3792eb451c294cf Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Wed, 4 Oct 2023 12:15:15 -0700 Subject: [PATCH] nx: debounce fresh insertion Signed-off-by: Varun Patil --- src/native/days.ts | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/native/days.ts b/src/native/days.ts index 6145ff45..f1a3bb06 100644 --- a/src/native/days.ts +++ b/src/native/days.ts @@ -91,10 +91,25 @@ export function mergeDay(current: IPhoto[], incoming: IPhoto[]): void { * Does not update the passed objects in any way * @param current Photos from day response */ -export function processFreshServerDay(dayId: number, photos: IPhoto[]): void { - const auids = photos.map((p) => p.auid).filter((a) => !!a) as number[]; - if (!auids.length) return; - nativex.setHasRemote(JSON.stringify(auids), true); +export function processFreshServerDay(this: any, dayId: number, photos: IPhoto[]): void { + const queue: Set = (this.pfsdq ??= new Set()); + + // Add to queue + for (const photo of photos) { + if (photo.auid) queue.add(photo.auid); + } + + // Debounce + utils.setRenewingTimeout( + this, + 'pfsdq_timer', + () => { + if (!queue.size) return; + nativex.setHasRemote(JSON.stringify(Array.from(queue)), true); + queue.clear(); + }, + 1000 + ); } /**