From 4d2fd7561f6bc7e43c23a48f31e5128cb9b47db3 Mon Sep 17 00:00:00 2001 From: Kibi Kelburton Date: Mon, 26 Jan 2026 09:31:02 +0100 Subject: [PATCH] possible performance optimization --- src/inc/lib.mjs | 4 ++-- src/inc/routes/apiv2/index.mjs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/inc/lib.mjs b/src/inc/lib.mjs index d072660..ec76db8 100644 --- a/src/inc/lib.mjs +++ b/src/inc/lib.mjs @@ -47,7 +47,7 @@ export default new class { tmp = "items.id in (select item_id from tags_assign where tag_id = 2 group by item_id)"; break; case 2: // untagged - tmp = "items.id not in (select item_id from tags_assign group by item_id)"; + tmp = "not exists (select 1 from tags_assign where item_id = items.id)"; break; case 3: // all tmp = "1 = 1"; @@ -94,7 +94,7 @@ export default new class { const untagged = +(await db` select count(*) as total from "items" - where id not in (select item_id from tags_assign group by item_id) and active = true + where not exists (select 1 from tags_assign where item_id = items.id) and active = true `)[0].total; const sfw = +(await db` select count(*) as total diff --git a/src/inc/routes/apiv2/index.mjs b/src/inc/routes/apiv2/index.mjs index 74dc282..398eda1 100644 --- a/src/inc/routes/apiv2/index.mjs +++ b/src/inc/routes/apiv2/index.mjs @@ -40,7 +40,7 @@ export default router => { active = 'true' ${isFav ? db`and fu."user" = ${user}` : db`and items.username ilike ${user}`} ${tag ? db`and tags.normalized ilike '%' || slugify(${tag}) || '%'` : db``} - ${!hasSession && globalfilter ? db`and items.id not in (select item_id from tags_assign where item_id = items.id and (${db.unsafe(globalfilter)}))` : db``} + ${!hasSession && globalfilter ? db`and not exists (select 1 from tags_assign where item_id = items.id and (${db.unsafe(globalfilter)}))` : db``} order by random() limit 1 `;