hydrateEvents: refactor a separate hydrateAuthors function
This commit is contained in:
parent
2ff96d2403
commit
4dfd958718
|
@ -17,14 +17,26 @@ async function hydrateEvents(opts: HydrateEventOpts): Promise<DittoEvent[]> {
|
||||||
return events;
|
return events;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (relations.includes('author')) {
|
for (const relation in relations) {
|
||||||
|
switch (relation) {
|
||||||
|
case 'author':
|
||||||
|
await hydrateAuthors({ events, storage, signal });
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return events;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function hydrateAuthors(opts: Omit<HydrateEventOpts, 'relations'>): Promise<DittoEvent[]> {
|
||||||
|
const { events, storage, signal } = opts;
|
||||||
|
|
||||||
const pubkeys = new Set([...events].map((event) => event.pubkey));
|
const pubkeys = new Set([...events].map((event) => event.pubkey));
|
||||||
const authors = await storage.query([{ kinds: [0], authors: [...pubkeys], limit: pubkeys.size }], { signal });
|
const authors = await storage.query([{ kinds: [0], authors: [...pubkeys], limit: pubkeys.size }], { signal });
|
||||||
|
|
||||||
for (const event of events) {
|
for (const event of events) {
|
||||||
event.author = authors.find((author) => author.pubkey === event.pubkey);
|
event.author = authors.find((author) => author.pubkey === event.pubkey);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return events;
|
return events;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue