diff --git a/src/storages/hydrate.ts b/src/storages/hydrate.ts index a30608ca..ea2d8da9 100644 --- a/src/storages/hydrate.ts +++ b/src/storages/hydrate.ts @@ -65,10 +65,6 @@ async function hydrateEvents(opts: HydrateOpts): Promise { cache.push(event); } - for (const event of await gatherZapSender({ events: cache, store, signal })) { - cache.push(event); - } - const stats = { authors: await gatherAuthorStats(cache, kysely as Kysely), events: await gatherEventStats(cache, kysely as Kysely), @@ -230,13 +226,26 @@ function gatherQuotes({ events, store, signal }: HydrateOpts): Promise { - const pubkeys = new Set(events.map((event) => { + const pubkeys = new Set(); + + for (const event of events) { if (event.kind === 9735) { - const pubkey = event.tags.find(([name]) => name === 'p')?.[1]; - if (pubkey) return pubkey; + const zapReceiver = event.tags.find(([name]) => name === 'p')?.[1]; + if (zapReceiver) { + pubkeys.add(zapReceiver); + } + + const zapRequestString = event?.tags?.find(([name]) => name === 'description')?.[1]; + const zapRequest = n.json().pipe(n.event()).optional().catch(undefined).parse(zapRequestString); + // By getting the pubkey from the zap request we guarantee who is the sender + // some clients don't put the P tag in the zap receipt... + const zapSender = zapRequest?.pubkey; + if (zapSender) { + pubkeys.add(zapSender); + } } - return event.pubkey; - })); + pubkeys.add(event.pubkey); + } return store.query( [{ kinds: [0], authors: [...pubkeys], limit: pubkeys.size }], @@ -336,29 +345,6 @@ function gatherZapped({ events, store, signal }: HydrateOpts): Promise { - const pubkeys = new Set(); - - for (const event of events) { - if (event.kind === 9735) { - const zapRequestString = event?.tags?.find(([name]) => name === 'description')?.[1]; - const zapRequest = n.json().pipe(n.event()).optional().catch(undefined).parse(zapRequestString); - // By getting the pubkey from the zap request we guarantee who is the sender - // some clients don't put the P tag in the zap receipt... - const zapSender = zapRequest?.pubkey; - if (zapSender) { - pubkeys.add(zapSender); - } - } - } - - return store.query( - [{ kinds: [0], limit: pubkeys.size }], - { signal }, - ); -} - /** Collect author stats from the events. */ async function gatherAuthorStats( events: DittoEvent[],