From 78457335c67b7ab9c571772a1dba409246de7f4d Mon Sep 17 00:00:00 2001 From: Gigi Date: Sat, 18 Oct 2025 20:43:02 +0200 Subject: [PATCH] refactor: simplify nostrverse highlights loading to direct query - Use direct queryEvents with kind:9802 filter instead of service wrapper - Add streaming with onEvent callback for immediate UI updates - Track first event timing for performance analysis - Remove unused fetchNostrverseHighlights import --- src/components/Debug.tsx | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/components/Debug.tsx b/src/components/Debug.tsx index a03835ab..1d632045 100644 --- a/src/components/Debug.tsx +++ b/src/components/Debug.tsx @@ -18,7 +18,6 @@ import { Bookmark } from '../types/bookmarks' import { useBookmarksUI } from '../hooks/useBookmarksUI' import { useSettings } from '../hooks/useSettings' import { fetchHighlights, fetchHighlightsFromAuthors } from '../services/highlightService' -import { fetchNostrverseHighlights } from '../services/nostrverseService' import { fetchContacts } from '../services/contactService' const defaultPayload = 'The quick brown fox jumps over the lazy dog.' @@ -504,10 +503,25 @@ const Debug: React.FC = ({ setIsLoadingHighlights(true) setTLoadHighlights(null) setTFirstHighlight(null) - DebugBus.info('debug', 'Loading nostrverse highlights...') + DebugBus.info('debug', 'Loading nostrverse highlights (kind:9802)...') try { - const all = await fetchNostrverseHighlights(relayPool, 100) - setHighlightEvents(all.map(h => ({ ...h, pubkey: h.pubkey, created_at: h.created_at, id: h.id, kind: 9802, tags: [], content: h.content, sig: '' } as NostrEvent))) + let firstEventTime: number | null = null + const seenIds = new Set() + const { queryEvents } = await import('../services/dataFetch') + + const events = await queryEvents(relayPool, { kinds: [9802], limit: 100 }, { + onEvent: (evt) => { + if (seenIds.has(evt.id)) return + seenIds.add(evt.id) + if (firstEventTime === null) { + firstEventTime = performance.now() - start + setTFirstHighlight(Math.round(firstEventTime)) + } + setHighlightEvents(prev => [...prev, evt]) + } + }) + + DebugBus.info('debug', `Loaded ${events.length} nostrverse highlights`) } finally { setIsLoadingHighlights(false) const elapsed = Math.round(performance.now() - start)