possible performance optimization

This commit is contained in:
2026-01-26 09:31:02 +01:00
parent c4bb21bc31
commit 4d2fd7561f
2 changed files with 3 additions and 3 deletions

View File

@@ -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)"; tmp = "items.id in (select item_id from tags_assign where tag_id = 2 group by item_id)";
break; break;
case 2: // untagged 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; break;
case 3: // all case 3: // all
tmp = "1 = 1"; tmp = "1 = 1";
@@ -94,7 +94,7 @@ export default new class {
const untagged = +(await db` const untagged = +(await db`
select count(*) as total select count(*) as total
from "items" 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; `)[0].total;
const sfw = +(await db` const sfw = +(await db`
select count(*) as total select count(*) as total

View File

@@ -40,7 +40,7 @@ export default router => {
active = 'true' active = 'true'
${isFav ? db`and fu."user" = ${user}` : db`and items.username ilike ${user}`} ${isFav ? db`and fu."user" = ${user}` : db`and items.username ilike ${user}`}
${tag ? db`and tags.normalized ilike '%' || slugify(${tag}) || '%'` : db``} ${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() order by random()
limit 1 limit 1
`; `;