From 213001b139a565fee99229614501764ff2739aae Mon Sep 17 00:00:00 2001 From: elpatron Date: Fri, 29 May 2026 20:20:34 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20Sync-Queue-Coalescing=20nach=20chronolog?= =?UTF-8?q?ischer=20ID=20statt=20Delete-Priorit=C3=A4t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Nach Löschen und erneutem Anlegen wurde der Create-Eintrag fälschlich verworfen, weil Deletes immer bevorzugt wurden — jetzt gewinnt die höchste Queue-ID. Co-authored-by: Cursor --- client/src/services/sync.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/client/src/services/sync.ts b/client/src/services/sync.ts index 0aad1be..a6c41ca 100644 --- a/client/src/services/sync.ts +++ b/client/src/services/sync.ts @@ -32,7 +32,11 @@ function entityKey(item: SyncQueueItem): string { return `${item.type}:${item.payloadId}` } -// Keep only the latest queue entry per entity; delete wins over create/update. +function latestQueueItem(items: SyncQueueItem[]): SyncQueueItem { + return items.reduce((a, b) => ((a.id ?? 0) > (b.id ?? 0) ? a : b)) +} + +// Keep only the latest queue entry per entity (highest auto-increment id = most recent action). async function coalesceSyncQueue(logbookId: string): Promise { const pending = await db.syncQueue.where({ logbookId }).toArray() if (pending.length <= 1) return pending @@ -49,11 +53,7 @@ async function coalesceSyncQueue(logbookId: string): Promise { const staleIds: number[] = [] for (const group of byEntity.values()) { - const deletes = group.filter((item) => item.action === 'delete') - const latest = - deletes.length > 0 - ? deletes.reduce((a, b) => ((a.id ?? 0) > (b.id ?? 0) ? a : b)) - : group.reduce((a, b) => ((a.id ?? 0) > (b.id ?? 0) ? a : b)) + const latest = latestQueueItem(group) kept.push(latest) for (const item of group) {