From 74ef00e9d8181e94db3acde341c5fda14b8e010e Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Fri, 29 Nov 2024 23:39:14 -0300 Subject: [PATCH] refactor(getIdsBySearch): do not search if the search content is empty --- src/utils/search.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/utils/search.ts b/src/utils/search.ts index 420b0812..da1e4127 100644 --- a/src/utils/search.ts +++ b/src/utils/search.ts @@ -87,6 +87,13 @@ export async function getIdsBySearch( query = query.where('pubkey', 'in', pubkeys); } + // If there is not a specific content to search, return the query already + // This is useful if the person only makes a query search such as `domain:patrickdosreis.com` + if (!parsedSearch.length) { + const ids = new Set((await query.execute()).map(({ id }) => id)); + return ids; + } + let fallbackQuery = query; if (parsedSearch) { query = query.where('search', '@@', sql`phraseto_tsquery(${parsedSearch})`);