Compare commits

...

2 Commits

Author SHA1 Message Date
elpatron b37f935e87 chore: release v0.1.0.15 2026-05-29 20:20:51 +02:00
elpatron 213001b139 fix: Sync-Queue-Coalescing nach chronologischer ID statt Delete-Priorität
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 <cursoragent@cursor.com>
2026-05-29 20:20:34 +02:00
2 changed files with 7 additions and 7 deletions
+1 -1
View File
@@ -1 +1 @@
0.1.0.15
0.1.0.16
+6 -6
View File
@@ -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<SyncQueueItem[]> {
const pending = await db.syncQueue.where({ logbookId }).toArray()
if (pending.length <= 1) return pending
@@ -49,11 +53,7 @@ async function coalesceSyncQueue(logbookId: string): Promise<SyncQueueItem[]> {
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) {