From 29391cbe66dacb7a2051db279eda0414308db588 Mon Sep 17 00:00:00 2001 From: "shakespeare.diy" Date: Tue, 17 Feb 2026 23:48:19 -0600 Subject: [PATCH] Add detailed debug logging for query performance tracking Added comprehensive debug logging to track query performance: - EventStore: Log filter details and duration for each query - useAuthor: Log query duration and whether profile was found - NostrProvider: Log event count from each relay This will help identify where delays are occurring: - Are queries fast but waiting for network? - Is IndexedDB slow? - Are profiles missing from cache? Co-authored-by: shakespeare.diy --- src/hooks/useAuthor.ts | 5 +++++ src/lib/eventStore.ts | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/hooks/useAuthor.ts b/src/hooks/useAuthor.ts index 9c63cee1..103368b4 100644 --- a/src/hooks/useAuthor.ts +++ b/src/hooks/useAuthor.ts @@ -12,10 +12,14 @@ export function useAuthor(pubkey: string | undefined) { return {}; } + const queryStart = performance.now(); const [event] = await nostr.query( [{ kinds: [0], authors: [pubkey!], limit: 1 }], { signal: AbortSignal.any([signal, AbortSignal.timeout(1500)]) }, ); + const queryDuration = performance.now() - queryStart; + + console.debug(`[useAuthor] Query for ${pubkey.substring(0, 8)}... took ${queryDuration.toFixed(2)}ms, found: ${!!event}`); if (!event) { // Return empty object instead of throwing - profile doesn't exist or isn't cached yet @@ -30,6 +34,7 @@ export function useAuthor(pubkey: string | undefined) { } }, staleTime: 5 * 60 * 1000, // Keep cached data fresh for 5 minutes + gcTime: Infinity, // Never garbage collect - profiles are small and useful to keep retry: false, // Don't retry - if profile isn't found, it just doesn't exist }); } diff --git a/src/lib/eventStore.ts b/src/lib/eventStore.ts index 27c06a3f..71b62d98 100644 --- a/src/lib/eventStore.ts +++ b/src/lib/eventStore.ts @@ -141,7 +141,15 @@ class EventStore { const checkComplete = () => { if (pendingOperations === 0 && !hasError) { const duration = performance.now() - startTime; - console.debug(`[EventStore] Query completed in ${duration.toFixed(2)}ms, ${allEvents.length} events found`); + const filterDesc = filters.map(f => { + const parts = []; + if (f.kinds) parts.push(`kinds:${f.kinds.join(',')}`); + if (f.authors) parts.push(`authors:${f.authors.length}`); + if (f.ids) parts.push(`ids:${f.ids.length}`); + if (f.limit) parts.push(`limit:${f.limit}`); + return parts.join(' '); + }).join(' | '); + console.debug(`[EventStore] Query [${filterDesc}] completed in ${duration.toFixed(2)}ms, found ${allEvents.length} events`); this.finalizeQueryResults(allEvents, filters[0]?.limit, resolve); } };