From 4e86b6bf3f987c9a2ffe1a502a1ab43e00cf99de Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 10 Feb 2025 16:21:01 -0600 Subject: [PATCH] hydrate: quotes must be gathered in a separate step --- src/storages/hydrate.ts | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/storages/hydrate.ts b/src/storages/hydrate.ts index a656d590..36df74f6 100644 --- a/src/storages/hydrate.ts +++ b/src/storages/hydrate.ts @@ -34,6 +34,10 @@ async function hydrateEvents(opts: HydrateOpts): Promise { cache.push(event); } + for (const event of await gatherQuotes({ events: cache, store, signal })) { + cache.push(event); + } + for (const event of await gatherProfiles({ events: cache, store, signal })) { cache.push(event); } @@ -198,13 +202,6 @@ function gatherRelatedEvents({ events, store, signal }: HydrateOpts): Promise(); for (const event of events) { - // Quoted events - if (event.kind === 1) { - const id = findQuoteTag(event.tags)?.[1] || findQuoteInContent(event.content); - if (id) { - ids.add(id); - } - } // Reposted events if (event.kind === 6) { const id = event.tags.find(([name]) => name === 'e')?.[1]; @@ -242,6 +239,25 @@ function gatherRelatedEvents({ events, store, signal }: HydrateOpts): Promise { + const ids = new Set(); + + for (const event of events) { + if (event.kind === 1) { + const id = findQuoteTag(event.tags)?.[1] || findQuoteInContent(event.content); + if (id) { + ids.add(id); + } + } + } + + return store.query( + [{ ids: [...ids], limit: ids.size }], + { signal }, + ); +} + /** Collect profiles from the events. */ async function gatherProfiles({ events, store, signal }: HydrateOpts): Promise { const pubkeys = new Set();