Performance improvement for counting image category tags

This commit is contained in:
Matthew Barbour 2020-06-11 18:10:46 -05:00 committed by Shish
parent b2405166b3
commit 04cde74226

View File

@ -85,14 +85,12 @@ class TagCategories extends Extension
); );
if (in_array($type, $types)) { if (in_array($type, $types)) {
$event->add_querylet( $event->add_querylet(
new Querylet("EXISTS ( new Querylet("(
SELECT 1 SELECT count(distinct t.id)
FROM image_tags it FROM tags t
LEFT JOIN tags t ON it.tag_id = t.id INNER JOIN image_tags it ON it.tag_id = t.id AND images.id = it.image_id
WHERE images.id = it.image_id WHERE LOWER(t.tag) LIKE LOWER('$type:%')) $cmp $count
GROUP BY image_id ")
HAVING SUM(CASE WHEN LOWER(t.tag) LIKE LOWER('$type:%') THEN 1 ELSE 0 END) $cmp $count
)")
); );
} }
} }