we can also optimise one negative tag in the same way

This commit is contained in:
Shish 2020-02-04 23:49:54 +00:00
parent b81a95129c
commit e971d10d41

View file

@ -894,24 +894,26 @@ class Image
");
}
// one positive tag sorted by ID - we can fetch this from the
// image_tags table, and do the offset / limit there, which is
// 10x faster than fetching all the image_tags and doing the
// offset / limit on the result.
// one tag sorted by ID - we can fetch this from the image_tags table,
// and do the offset / limit there, which is 10x faster than fetching
// all the image_tags and doing the offset / limit on the result.
elseif (
$positive_tag_count === 1
&& $negative_tag_count === 0
(
($positive_tag_count === 1 && $negative_tag_count === 0)
|| ($positive_tag_count === 0 && $negative_tag_count === 1)
)
&& empty($img_conditions)
&& $order == "id DESC"
&& !is_null($offset)
&& !is_null($limit)
) {
$in = $positive_tag_count === 1 ? "IN" : "NOT IN";
$query = new Querylet("
SELECT images.*
FROM images INNER JOIN (
SELECT it.image_id
FROM image_tags it
WHERE it.tag_id IN (
WHERE it.tag_id $in (
SELECT id
FROM tags
WHERE LOWER(tag) LIKE LOWER(:tag)