UnattachedMedia: return early when querying nothing

This commit is contained in:
Alex Gleason 2024-05-04 13:14:03 -05:00
parent fbf3011e3e
commit 3770d8a0dd
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 6 additions and 3 deletions

View File

@ -54,15 +54,18 @@ function deleteUnattachedMediaByUrl(url: string) {
} }
/** Get unattached media by IDs. */ /** 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() return selectUnattachedMediaQuery()
.where('id', 'in', ids) .where('id', 'in', ids)
.execute(); .execute();
} }
/** Delete rows as an event with media is being created. */ /** Delete rows as an event with media is being created. */
function deleteAttachedMedia(pubkey: string, urls: string[]) { async function deleteAttachedMedia(pubkey: string, urls: string[]): Promise<void> {
return db.deleteFrom('unattached_media') if (!urls.length) return;
await db.deleteFrom('unattached_media')
.where('pubkey', '=', pubkey) .where('pubkey', '=', pubkey)
.where('url', 'in', urls) .where('url', 'in', urls)
.execute(); .execute();