From 6ea71865f160e75e57970dcea9087e3c33e1570e Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 17 Oct 2024 15:26:23 -0500 Subject: [PATCH] hydrate: build fallback authors during gatherAuthors step --- src/storages/hydrate.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/storages/hydrate.ts b/src/storages/hydrate.ts index c8b9b97e..8b2067e9 100644 --- a/src/storages/hydrate.ts +++ b/src/storages/hydrate.ts @@ -99,8 +99,7 @@ export function assembleEvents( })); for (const event of a) { - event.author = b.find((e) => matchFilter({ kinds: [0], authors: [event.pubkey] }, e)) ?? - fallbackAuthor(event.pubkey); + event.author = b.find((e) => matchFilter({ kinds: [0], authors: [event.pubkey] }, e)); event.user = b.find((e) => matchFilter({ kinds: [30382], authors: [admin], '#d': [event.pubkey] }, e)); event.info = b.find((e) => matchFilter({ kinds: [30383], authors: [admin], '#d': [event.id] }, e)); @@ -231,19 +230,29 @@ function gatherQuotes({ events, store, signal }: HydrateOpts): Promise { +async function gatherAuthors({ events, store, signal }: HydrateOpts): Promise { const pubkeys = new Set(events.map((event) => { - if (event.kind === 9735) { + if (event.kind === 9735) { // FIXME: This code doesn't belong in this function. const pubkey = event.tags.find(([name]) => name === 'p')?.[1]; if (pubkey) return pubkey; } return event.pubkey; })); - return store.query( + const authors = await store.query( [{ kinds: [0], authors: [...pubkeys], limit: pubkeys.size }], { signal }, ); + + for (const pubkey of pubkeys) { + const author = authors.find((e) => matchFilter({ kinds: [0], authors: [pubkey] }, e)); + if (author) { + const fallback = fallbackAuthor(pubkey); + authors.push(fallback); + } + } + + return authors; } /** Collect users from the events. */