db/events: perform multiple filters with one union query, greatly simplify logic
This commit is contained in:
parent
4602b85afe
commit
59b7a3eed8
|
@ -106,11 +106,10 @@ function getFilterQuery(filter: DittoFilter) {
|
||||||
|
|
||||||
/** Get events for filters from the database. */
|
/** Get events for filters from the database. */
|
||||||
async function getFilters<K extends number>(filters: DittoFilter<K>[]): Promise<SignedEvent<K>[]> {
|
async function getFilters<K extends number>(filters: DittoFilter<K>[]): Promise<SignedEvent<K>[]> {
|
||||||
const queries = filters
|
const events = await filters
|
||||||
.map(getFilterQuery)
|
.map(getFilterQuery)
|
||||||
.map((query) => query.execute());
|
.reduce((acc, curr) => acc.union(curr))
|
||||||
|
.execute();
|
||||||
const events = (await Promise.all(queries)).flat();
|
|
||||||
|
|
||||||
return events.map((event) => (
|
return events.map((event) => (
|
||||||
{ ...event, tags: JSON.parse(event.tags) } as SignedEvent<K>
|
{ ...event, tags: JSON.parse(event.tags) } as SignedEvent<K>
|
||||||
|
|
Loading…
Reference in New Issue