possible random performance improvement ?
This commit is contained in:
@@ -31,22 +31,28 @@ export default router => {
|
||||
|
||||
const randomId = Math.floor(Math.random() * maxId);
|
||||
|
||||
let tagId = null;
|
||||
if (tag) {
|
||||
const tagResult = await db`select id from "tags" where normalized ilike '%' || slugify(${tag}) || '%' limit 1`;
|
||||
if (tagResult.length === 0) {
|
||||
return res.json({ success: false, items: [] });
|
||||
}
|
||||
tagId = tagResult[0].id;
|
||||
}
|
||||
|
||||
// Reusable query parts
|
||||
const baseQuery = db`
|
||||
select "items".*
|
||||
from "items"
|
||||
${isFav
|
||||
? db`join "favorites" on "favorites".item_id = "items".id join "user" as fu on fu.id = "favorites".user_id`
|
||||
: db``
|
||||
}
|
||||
left join tags_assign on tags_assign.item_id = items.id
|
||||
left join tags on tags.id = tags_assign.tag_id
|
||||
where
|
||||
${db.unsafe(modequery)} and
|
||||
mime ilike ${mime} and
|
||||
active = 'true'
|
||||
${isFav ? db`and fu."user" = ${user}` : db`and items.username ilike ${user}`}
|
||||
${tag ? db`and tags.normalized ilike '%' || slugify(${tag}) || '%'` : db``}
|
||||
${tagId ? db`and exists (select 1 from tags_assign where item_id = items.id and tag_id = ${tagId})` : db``}
|
||||
${!hasSession && globalfilter ? db`and not exists (select 1 from tags_assign where item_id = items.id and (${db.unsafe(globalfilter)}))` : db``}
|
||||
`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user