Fix expired queue entries persisting past MAX_AGE_MS

The flush function pruned expired entries in memory but re-read from
localStorage before writing back, so the age filter was never persisted.
Apply the age cutoff to the final write filter and remove the early
return that skipped the write entirely on full send failure.

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-04-16 13:40:45 +04:00
parent eafca11c82
commit d63ce1f68b

View File

@@ -93,14 +93,13 @@ export async function flush(bannerId: string): Promise<void> {
}
}
if (sentTimestamps.length === 0) {
return;
}
const sentSet = new Set(sentTimestamps);
const cutoff = now - MAX_AGE_MS;
const current = readQueue(bannerId);
writeQueue(
bannerId,
current.filter((entry) => !sentSet.has(entry.timestamp)),
current.filter(
(entry) => !sentSet.has(entry.timestamp) && entry.timestamp > cutoff,
),
);
}