fix(05-review): NEW-WR-01 emit delete changes when server returns zero events (whole-cache clear)

Pre-capture all currently-cached rows into pendingDeleteRows before the whole-cache
db.delete() when seenUids.length === 0. The existing >0 branch behavior is unchanged.
Adds a regression test verifying onChanges receives one delete change per cached row
on a full-calendar clear.
This commit is contained in:
Lucas Berger
2026-06-09 22:39:11 -04:00
parent c7ef5811d1
commit 17756fc523
2 changed files with 54 additions and 0 deletions
+8
View File
@@ -256,6 +256,14 @@ export async function syncCalendar(
notInArray(calendarEvents.uid, seenUids),
),
)
} else if (onChanges) {
// NEW-WR-01: server returned zero events → entire calendar cache will be cleared.
// Capture ALL currently-cached rows before the delete so delete-change events
// are emitted for each one. Without this, bulk/clear deletions were silently dropped.
pendingDeleteRows = await db
.select({ uid: calendarEvents.uid, title: calendarEvents.title })
.from(calendarEvents)
.where(eq(calendarEvents.calendarId, cal.id))
}
if (seenUids.length > 0) {