From e8aa483ca9f27462331e08c8e80bd257adca064f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9line?= <42832501+celine-s@users.noreply.github.com> Date: Fri, 27 Sep 2024 07:45:12 +0200 Subject: [PATCH] feat: check for empty cachtags (#4) --- src/cache-tags.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/cache-tags.ts b/src/cache-tags.ts index f6fc984..5af6bd9 100644 --- a/src/cache-tags.ts +++ b/src/cache-tags.ts @@ -42,6 +42,10 @@ export const generateQueryId = (document: DocumentNode, va */ export const storeQueryCacheTags = async (queryId: string, cacheTags: CacheTag[]) => { + if (!cacheTags?.length) { + return; + } + await sql.query( `INSERT INTO query_cache_tags VALUES ${cacheTags.map((cacheTag) => `('${queryId}', '${cacheTag}')`).join()} ON CONFLICT DO NOTHING`, ); @@ -55,6 +59,9 @@ export const storeQueryCacheTags = async (queryId: string, cacheTags: CacheTag[] */ export const queriesReferencingCacheTags = async (cacheTags: CacheTag[]): Promise => { + if (!cacheTags?.length) { + return []; + } const { rows }: { rows: { query_id: string }[] } = await sql.query( `SELECT DISTINCT query_id FROM query_cache_tags WHERE cache_tag IN (${cacheTags.map((cacheTag) => `'${cacheTag}'`).join(', ')})`, ); @@ -69,5 +76,8 @@ export const queriesReferencingCacheTags = async (cacheTags: CacheTag[]): Promis */ export const deleteQueries = async (queryIds: string[]) => { + if (!queryIds?.length) { + return; + } await sql.query(`DELETE FROM query_cache_tags WHERE query_id IN (${queryIds.map((id) => `'${id}'`).join(', ')})`); };