fix: stabilize sync process by rounding cutoff date to midnight UTC and update cleanup logic for user databases

This commit is contained in:
Anish Sarkar 2026-02-04 19:58:47 +05:30
parent 6989059e94
commit dec85b6417
2 changed files with 67 additions and 19 deletions

View file

@ -38,10 +38,14 @@ function deduplicateAndSort(items: InboxItem[]): InboxItem[] {
/**
* Calculate the cutoff date for sync window
* IMPORTANT: Rounds to the start of the day (midnight UTC) to ensure stable values
* across re-renders. Without this, millisecond differences cause multiple syncs!
*/
function getSyncCutoffDate(): string {
const cutoff = new Date();
cutoff.setDate(cutoff.getDate() - SYNC_WINDOW_DAYS);
// Round to start of day to prevent millisecond differences causing duplicate syncs
cutoff.setUTCHours(0, 0, 0, 0);
return cutoff.toISOString();
}