From 914738abb49c2af54205f9324f979ac57d8d90b8 Mon Sep 17 00:00:00 2001 From: Gigi Date: Sun, 19 Oct 2025 12:18:46 +0200 Subject: [PATCH] fix: force full sync when map is empty - If currentProgressMap is empty, do a full sync (no 'since' filter) - This ensures first load gets all events, not just recent ones - Incremental sync only happens when we already have data - This was the bug: lastSynced was preventing initial load of events --- src/services/readingProgressController.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/services/readingProgressController.ts b/src/services/readingProgressController.ts index d0234e42..c1d0043f 100644 --- a/src/services/readingProgressController.ts +++ b/src/services/readingProgressController.ts @@ -129,19 +129,21 @@ class ReadingProgressController { this.lastLoadedPubkey = pubkey try { - // Query events - this checks both local store AND relays - // The queryEvents function is smart enough to check local first - const lastSynced = force ? null : this.getLastSyncedAt(pubkey) + // Query events from relays + // Force full sync if map is empty (first load) or if explicitly forced + const needsFullSync = force || this.currentProgressMap.size === 0 + const lastSynced = needsFullSync ? null : this.getLastSyncedAt(pubkey) + const filter: any = { kinds: [KINDS.ReadingProgress], authors: [pubkey] } - if (lastSynced && !force) { + if (lastSynced && !needsFullSync) { filter.since = lastSynced - console.log('📊 [ReadingProgress] Incremental sync from relays since', new Date(lastSynced * 1000).toISOString()) + console.log('📊 [ReadingProgress] Incremental sync since', new Date(lastSynced * 1000).toISOString()) } else { - console.log('📊 [ReadingProgress] Full sync from relays') + console.log('📊 [ReadingProgress] Full sync (map size:', this.currentProgressMap.size + ')') } const relayEvents = await queryEvents(relayPool, filter, { relayUrls: RELAYS })