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:
@@ -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,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user