From 59b7a3eed8119be463475e21fc1046ff1dfbcc8d Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 16 Aug 2023 15:32:02 -0500 Subject: [PATCH] db/events: perform multiple filters with one union query, greatly simplify logic --- src/db/events.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/db/events.ts b/src/db/events.ts index 2f29189..15e24f4 100644 --- a/src/db/events.ts +++ b/src/db/events.ts @@ -106,11 +106,10 @@ function getFilterQuery(filter: DittoFilter) { /** Get events for filters from the database. */ async function getFilters(filters: DittoFilter[]): Promise[]> { - const queries = filters + const events = await filters .map(getFilterQuery) - .map((query) => query.execute()); - - const events = (await Promise.all(queries)).flat(); + .reduce((acc, curr) => acc.union(curr)) + .execute(); return events.map((event) => ( { ...event, tags: JSON.parse(event.tags) } as SignedEvent