From 3770d8a0dd11833949327b290db1e3b6f7cacb17 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 4 May 2024 13:14:03 -0500 Subject: [PATCH] UnattachedMedia: return early when querying nothing --- src/db/unattached-media.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/db/unattached-media.ts b/src/db/unattached-media.ts index 415c110..960abe8 100644 --- a/src/db/unattached-media.ts +++ b/src/db/unattached-media.ts @@ -54,15 +54,18 @@ function deleteUnattachedMediaByUrl(url: string) { } /** Get unattached media by IDs. */ -function getUnattachedMediaByIds(ids: string[]) { +// deno-lint-ignore require-await +async function getUnattachedMediaByIds(ids: string[]) { + if (!ids.length) return []; return selectUnattachedMediaQuery() .where('id', 'in', ids) .execute(); } /** Delete rows as an event with media is being created. */ -function deleteAttachedMedia(pubkey: string, urls: string[]) { - return db.deleteFrom('unattached_media') +async function deleteAttachedMedia(pubkey: string, urls: string[]): Promise { + if (!urls.length) return; + await db.deleteFrom('unattached_media') .where('pubkey', '=', pubkey) .where('url', 'in', urls) .execute();