hydrateEvents: return early if the results would be empty
This commit is contained in:
parent
b8d01ea3de
commit
a2c3daade7
|
@ -99,6 +99,10 @@ function gatherReposts({ events, storage, signal }: HydrateOpts): Promise<DittoE
|
|||
}
|
||||
}
|
||||
|
||||
if (!ids.size) {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
return storage.query(
|
||||
[{ ids: [...ids], limit: ids.size }],
|
||||
{ signal },
|
||||
|
@ -118,6 +122,10 @@ function gatherQuotes({ events, storage, signal }: HydrateOpts): Promise<DittoEv
|
|||
}
|
||||
}
|
||||
|
||||
if (!ids.size) {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
return storage.query(
|
||||
[{ ids: [...ids], limit: ids.size }],
|
||||
{ signal },
|
||||
|
@ -128,6 +136,10 @@ function gatherQuotes({ events, storage, signal }: HydrateOpts): Promise<DittoEv
|
|||
function gatherAuthors({ events, storage, signal }: HydrateOpts): Promise<DittoEvent[]> {
|
||||
const pubkeys = new Set(events.map((event) => event.pubkey));
|
||||
|
||||
if (!pubkeys.size) {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
return storage.query(
|
||||
[{ kinds: [0], authors: [...pubkeys], limit: pubkeys.size }],
|
||||
{ signal },
|
||||
|
@ -138,6 +150,10 @@ function gatherAuthors({ events, storage, signal }: HydrateOpts): Promise<DittoE
|
|||
function gatherUsers({ events, storage, signal }: HydrateOpts): Promise<DittoEvent[]> {
|
||||
const pubkeys = new Set(events.map((event) => event.pubkey));
|
||||
|
||||
if (!pubkeys.size) {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
return storage.query(
|
||||
[{ kinds: [30361], authors: [Conf.pubkey], '#d': [...pubkeys], limit: pubkeys.size }],
|
||||
{ signal },
|
||||
|
@ -152,6 +168,10 @@ function gatherAuthorStats(events: DittoEvent[]): Promise<DittoTables['author_st
|
|||
.map((event) => event.pubkey),
|
||||
);
|
||||
|
||||
if (!pubkeys.size) {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
return db
|
||||
.selectFrom('author_stats')
|
||||
.selectAll()
|
||||
|
@ -167,6 +187,10 @@ function gatherEventStats(events: DittoEvent[]): Promise<DittoTables['event_stat
|
|||
.map((event) => event.id),
|
||||
);
|
||||
|
||||
if (!ids.size) {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
return db
|
||||
.selectFrom('event_stats')
|
||||
.selectAll()
|
||||
|
|
Loading…
Reference in New Issue