feat: Clean up orphaned sync queue items after logbook synchronization

Added functionality to remove orphaned queue items for logbooks that are no longer present in the database after synchronizing all logbooks. This ensures the sync queue remains accurate and up-to-date.
This commit is contained in:
2026-05-29 21:13:48 +02:00
parent aeb304baf6
commit fa8a381739
+13
View File
@@ -414,6 +414,19 @@ export async function syncAllLogbooks(): Promise<void> {
for (const lb of logbooks) { for (const lb of logbooks) {
await syncLogbook(lb.id) await syncLogbook(lb.id)
} }
// 3. Clean up orphaned queue items for logbooks no longer in db.logbooks.
// Re-read logbooks so any logbooks created during step 2 are included.
const freshLogbooks = await db.logbooks.toArray()
const freshKnownIds = new Set(freshLogbooks.map((l) => l.id))
const currentQueue = await db.syncQueue.toArray()
const orphanedIds = currentQueue
.filter((i) => !freshKnownIds.has(i.logbookId))
.map((i) => i.id!)
.filter(Boolean)
if (orphanedIds.length > 0) {
await db.syncQueue.bulkDelete(orphanedIds)
}
} catch (error) { } catch (error) {
console.error('Error synchronizing all logbooks:', error) console.error('Error synchronizing all logbooks:', error)
} finally { } finally {