hydrate: quotes must be gathered in a separate step

This commit is contained in:
Alex Gleason 2025-02-10 16:21:01 -06:00
parent 8267c170f0
commit 4e86b6bf3f
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -34,6 +34,10 @@ async function hydrateEvents(opts: HydrateOpts): Promise<DittoEvent[]> {
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<Di
const ids = new Set<string>();
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<Di
);
}
/** Collect quotes from the events. */
function gatherQuotes({ events, store, signal }: HydrateOpts): Promise<DittoEvent[]> {
const ids = new Set<string>();
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<DittoEvent[]> {
const pubkeys = new Set<string>();