From a2c3daade71f60aff49823f6c3efdc863057b6be Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 23 Apr 2024 21:32:48 -0500 Subject: [PATCH] hydrateEvents: return early if the results would be empty --- src/storages/hydrate.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/storages/hydrate.ts b/src/storages/hydrate.ts index 0ef84e0..1535571 100644 --- a/src/storages/hydrate.ts +++ b/src/storages/hydrate.ts @@ -99,6 +99,10 @@ function gatherReposts({ events, storage, signal }: HydrateOpts): Promise { 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 { 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 event.pubkey), ); + if (!pubkeys.size) { + return Promise.resolve([]); + } + return db .selectFrom('author_stats') .selectAll() @@ -167,6 +187,10 @@ function gatherEventStats(events: DittoEvent[]): Promise event.id), ); + if (!ids.size) { + return Promise.resolve([]); + } + return db .selectFrom('event_stats') .selectAll()