diff --git a/src/hooks/useAuthor.ts b/src/hooks/useAuthor.ts index ed3066d0..644069c2 100644 --- a/src/hooks/useAuthor.ts +++ b/src/hooks/useAuthor.ts @@ -18,10 +18,6 @@ export function useAuthor(pubkey: string | undefined) { const { nostr } = useNostr(); const { config } = useAppContext(); - // Get the effective relays (same ones used by the pool) - const effectiveRelays = getEffectiveRelays(config.relayMetadata, config.useAppRelays); - const readRelayUrls = effectiveRelays.relays.filter(r => r.read).map(r => r.url); - return useQuery<{ event?: NostrEvent; metadata?: NostrMetadata }>({ queryKey: ['author', pubkey ?? ''], queryFn: async ({ signal }) => { @@ -29,6 +25,11 @@ export function useAuthor(pubkey: string | undefined) { return {}; } + // Get the effective relays (same ones used by the pool) - do this inside queryFn + // so we have the latest relay configuration when the query executes + const effectiveRelays = getEffectiveRelays(config.relayMetadata, config.useAppRelays); + const readRelayUrls = effectiveRelays.relays.filter(r => r.read).map(r => r.url); + const combinedSignal = AbortSignal.any([signal, AbortSignal.timeout(5000)]); // Fast path: use the pool (races all relays, returns quickly via EOSE timeout) diff --git a/src/hooks/useAuthors.ts b/src/hooks/useAuthors.ts index dd41dbf3..60addb24 100644 --- a/src/hooks/useAuthors.ts +++ b/src/hooks/useAuthors.ts @@ -25,10 +25,6 @@ export function useAuthors(pubkeys: string[]) { const queryClient = useQueryClient(); const { config } = useAppContext(); - // Get the effective relays (same ones used by the pool) - const effectiveRelays = getEffectiveRelays(config.relayMetadata, config.useAppRelays); - const readRelayUrls = effectiveRelays.relays.filter(r => r.read).map(r => r.url); - // Deduplicate and sort for a stable query key const uniquePubkeys = [...new Set(pubkeys)].sort(); @@ -39,6 +35,11 @@ export function useAuthors(pubkeys: string[]) { return new Map(); } + // Get the effective relays (same ones used by the pool) - do this inside queryFn + // so we have the latest relay configuration when the query executes + const effectiveRelays = getEffectiveRelays(config.relayMetadata, config.useAppRelays); + const readRelayUrls = effectiveRelays.relays.filter(r => r.read).map(r => r.url); + const combinedSignal = AbortSignal.any([signal, AbortSignal.timeout(5000)]); // Fast path: use the pool (races all relays, returns quickly via EOSE timeout) @@ -68,6 +69,7 @@ export function useAuthors(pubkeys: string[]) { // individually with more time (5000ms vs 500ms EOSE timeout). const missing = uniquePubkeys.filter(pk => !found.has(pk)); if (missing.length > 0 && readRelayUrls.length > 0) { + console.log('[useAuthors] Loser race for', missing.length, 'missing profiles on', readRelayUrls.length, 'relays'); await new Promise((resolve) => { const needed = new Set(missing); let pending = readRelayUrls.length; @@ -77,6 +79,9 @@ export function useAuthors(pubkeys: string[]) { [{ kinds: [0], authors: missing, limit: missing.length }], { signal: combinedSignal }, ).then((relayEvents) => { + if (relayEvents.length > 0) { + console.log('[useAuthors] Found', relayEvents.length, 'profiles on', url); + } for (const event of relayEvents) { if (needed.has(event.pubkey)) { const parsed = parseAuthorEvent(event); @@ -87,11 +92,13 @@ export function useAuthors(pubkeys: string[]) { } if (needed.size === 0) resolve(); if (--pending === 0) resolve(); - }).catch(() => { + }).catch((err) => { + console.warn('[useAuthors] Relay failed:', url, err); if (--pending === 0) resolve(); }); } }); + console.log('[useAuthors] Loser race complete, still missing:', needed.size); } return authorMap;