From e971d10d413c265c0860f577a5f60d377825f9d0 Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 4 Feb 2020 23:49:54 +0000 Subject: [PATCH] we can also optimise one negative tag in the same way --- core/imageboard/image.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/core/imageboard/image.php b/core/imageboard/image.php index ff6428ce..049f7b38 100644 --- a/core/imageboard/image.php +++ b/core/imageboard/image.php @@ -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)