getFilters: return immediately if filters are empty

This commit is contained in:
Alex Gleason 2023-08-19 12:37:42 -05:00
parent 4a61ce26a9
commit 05a7a773fe
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 2 additions and 0 deletions

View File

@ -29,6 +29,7 @@ function getPool(): Pool {
/** Get events from a NIP-01 filter. */ /** Get events from a NIP-01 filter. */
function getFilters<K extends number>(filters: Filter<K>[], opts: GetFiltersOpts = {}): Promise<Event<K>[]> { function getFilters<K extends number>(filters: Filter<K>[], opts: GetFiltersOpts = {}): Promise<Event<K>[]> {
if (!filters.length) return Promise.resolve([]);
return new Promise((resolve) => { return new Promise((resolve) => {
let tid: number; let tid: number;
const results: Event[] = []; const results: Event[] = [];

View File

@ -108,6 +108,7 @@ async function getFilters<K extends number>(
filters: DittoFilter<K>[], filters: DittoFilter<K>[],
opts: GetFiltersOpts = {}, opts: GetFiltersOpts = {},
): Promise<Event<K>[]> { ): Promise<Event<K>[]> {
if (!filters.length) return Promise.resolve([]);
let query = filters.map(getFilterQuery).reduce((acc, curr) => acc.union(curr)); let query = filters.map(getFilterQuery).reduce((acc, curr) => acc.union(curr));
if (typeof opts.limit === 'number') { if (typeof opts.limit === 'number') {