From 6ea0fd292c63b5f958fa1a70bf3763e0bcc14b43 Mon Sep 17 00:00:00 2001 From: Gigi Date: Sat, 18 Oct 2025 00:14:33 +0200 Subject: [PATCH] fix: skip background event fetching when there are too many IDs Problem: With 400+ bookmarked events, trying to fetch all referenced events at once caused queryEvents to hang/timeout, making bookmarks appear to not load even though they were emitted. Solution: - Added MAX_IDS_TO_FETCH limit (100 IDs) - Added MAX_COORDS_TO_FETCH limit (100 coordinates) - If counts exceed limits, skip fetching and show bookmarks with IDs only - Bookmarks still appear immediately with placeholder data (IDs) - For smaller collections, metadata still loads in background This fixes the hanging issue for users with large bookmark collections - all 532 bookmarks will now appear instantly in the sidebar (showing IDs), without waiting for potentially slow/hanging queryEvents calls. --- src/services/bookmarkController.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/services/bookmarkController.ts b/src/services/bookmarkController.ts index 3ad0c04b..3bb53022 100644 --- a/src/services/bookmarkController.ts +++ b/src/services/bookmarkController.ts @@ -218,11 +218,14 @@ class BookmarkController { emitBookmarks(idToEvent) // Now fetch events progressively in background (non-blocking) - console.log('[bookmark] 🔧 Starting background fetch:', noteIds.length, 'note IDs and', coordinates.length, 'coordinates') + console.log('[bookmark] 🔧 Background fetch:', noteIds.length, 'note IDs and', coordinates.length, 'coordinates') - // Fetch regular events by ID (non-blocking) - if (noteIds.length > 0) { - console.log('[bookmark] 🔧 Fetching events by ID in background...') + // Skip fetching if there are too many (would be too slow) + const MAX_IDS_TO_FETCH = 100 + if (noteIds.length > MAX_IDS_TO_FETCH) { + console.log('[bookmark] ⏭️ Skipping event fetch (', noteIds.length, '> max', MAX_IDS_TO_FETCH, ') - showing IDs only') + } else if (noteIds.length > 0) { + console.log('[bookmark] 🔧 Fetching', noteIds.length, 'events by ID in background...') queryEvents( relayPool, { ids: Array.from(new Set(noteIds)) }, @@ -245,8 +248,11 @@ class BookmarkController { } // Fetch addressable events by coordinates (non-blocking) - if (coordinates.length > 0) { - console.log('[bookmark] 🔧 Fetching addressable events in background...') + const MAX_COORDS_TO_FETCH = 100 + if (coordinates.length > MAX_COORDS_TO_FETCH) { + console.log('[bookmark] ⏭️ Skipping coordinate fetch (', coordinates.length, '> max', MAX_COORDS_TO_FETCH, ') - showing IDs only') + } else if (coordinates.length > 0) { + console.log('[bookmark] 🔧 Fetching', coordinates.length, 'addressable events in background...') const byKind = new Map>() coordinates.forEach(coord => {