fix: follow-up grouped query for orphaned authors after first prefetch

First query fires with 1500ms timeout — fast path for most profiles.
After it resolves, check which pubkeys still have no cache entry and
fire one more grouped query for those orphans with 4000ms timeout.
Also handles the case where the first query fails entirely by retrying
the full batch. All grouped — never one subscription per pubkey.

Co-authored-by: shakespeare.diy <assistant@shakespeare.diy>
This commit is contained in:
shakespeare.diy
2026-02-18 10:46:28 -06:00
parent 399397117a
commit 01d9df86d3
+30 -1
View File
@@ -81,7 +81,36 @@ export function prefetchFeedData(
try { metadata = n.json().pipe(n.metadata()).parse(ev.content); } catch { /* skip */ }
seedAuthorCache(queryClient, ev.pubkey, { event: ev, metadata });
}
}).catch(() => {});
// Follow-up for orphans: pubkeys the first query didn't return within
// the timeout. Retry them in one grouped query under the same conditions.
const orphans = pubkeysToFetch.filter(
(pk) => queryClient.getQueryData(['author', pk]) === undefined,
);
if (orphans.length > 0) {
nostr.query(
[{ kinds: [0], authors: orphans }],
{ signal: AbortSignal.timeout(4000) },
).then((retryEvents) => {
for (const ev of retryEvents) {
let metadata: NostrMetadata | undefined;
try { metadata = n.json().pipe(n.metadata()).parse(ev.content); } catch { /* skip */ }
seedAuthorCache(queryClient, ev.pubkey, { event: ev, metadata });
}
}).catch(() => {});
}
}).catch(() => {
// First query failed entirely — retry the whole batch with more time.
nostr.query(
[{ kinds: [0], authors: pubkeysToFetch }],
{ signal: AbortSignal.timeout(4000) },
).then((retryEvents) => {
for (const ev of retryEvents) {
let metadata: NostrMetadata | undefined;
try { metadata = n.json().pipe(n.metadata()).parse(ev.content); } catch { /* skip */ }
seedAuthorCache(queryClient, ev.pubkey, { event: ev, metadata });
}
}).catch(() => {});
});
}
if (eventIdsToFetch.length > 0) {