possible performance optimization
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
`;
|
`;
|
||||||
|
|||||||
Reference in New Issue
Block a user