queries: get author from memory when possible
This commit is contained in:
parent
c2b25bc798
commit
2b1e97ee1b
|
@ -22,7 +22,7 @@ const getEvent = async <K extends number = number>(
|
|||
const { kind, relations, signal = AbortSignal.timeout(1000) } = opts;
|
||||
const microfilter: IdMicrofilter = { ids: [id] };
|
||||
|
||||
const [memoryEvent] = await memorelay.getFilters([microfilter], opts) as Event<K>[];
|
||||
const [memoryEvent] = await memorelay.getFilters([microfilter], opts) as eventsDB.DittoEvent<K>[];
|
||||
|
||||
if (memoryEvent && !relations) {
|
||||
return memoryEvent;
|
||||
|
@ -36,7 +36,20 @@ const getEvent = async <K extends number = number>(
|
|||
const dbEvent = await eventsDB.getFilters([filter], { limit: 1, signal })
|
||||
.then(([event]) => event);
|
||||
|
||||
// TODO: make this DRY-er.
|
||||
|
||||
if (dbEvent && !dbEvent.author) {
|
||||
const [author] = await memorelay.getFilters([{ kinds: [0], authors: [dbEvent.pubkey] }], opts);
|
||||
dbEvent.author = author;
|
||||
}
|
||||
|
||||
if (dbEvent) return dbEvent;
|
||||
|
||||
if (memoryEvent && !memoryEvent.author) {
|
||||
const [author] = await memorelay.getFilters([{ kinds: [0], authors: [memoryEvent.pubkey] }], opts);
|
||||
memoryEvent.author = author;
|
||||
}
|
||||
|
||||
if (memoryEvent) return memoryEvent;
|
||||
|
||||
return await reqmeister.req(microfilter).catch(() => undefined) as Event<K> | undefined;
|
||||
|
|
Loading…
Reference in New Issue