From 5d91c4b50752a84963c5ce19af8439d8f6aa9303 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 5 Jan 2024 18:04:24 -0600 Subject: [PATCH] EventsDB: normalizeFilters --- src/storages/events-db.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/storages/events-db.ts b/src/storages/events-db.ts index 143f4f6..0bff2bd 100644 --- a/src/storages/events-db.ts +++ b/src/storages/events-db.ts @@ -1,7 +1,7 @@ import { Conf } from '@/config.ts'; import { type DittoDB } from '@/db.ts'; import { Debug, type Event, Kysely, type SelectQueryBuilder } from '@/deps.ts'; -import { type DittoFilter } from '@/filter.ts'; +import { type DittoFilter, normalizeFilters } from '@/filter.ts'; import { isDittoInternalKind, isParameterizedReplaceableKind, isReplaceableKind } from '@/kinds.ts'; import { jsonMetaContentSchema } from '@/schemas/nostr.ts'; import { isNostrId, isURL } from '@/utils.ts'; @@ -264,12 +264,12 @@ class EventsDB implements EventStore { } /** Get events for filters from the database. */ - async getEvents( - filters: DittoFilter[], - opts: GetEventsOpts = {}, - ): Promise[]> { + async getEvents(filters: DittoFilter[], opts: GetEventsOpts = {}): Promise[]> { + filters = normalizeFilters(filters); // Improves performance of `{ kinds: [0], authors: ['...'] }` queries. + if (opts.signal?.aborted) return Promise.resolve([]); if (!filters.length) return Promise.resolve([]); + this.#debug('REQ', JSON.stringify(filters)); let query = this.getEventsQuery(filters);