From 320a92289b22833bd6814070294a91c6ae50f887 Mon Sep 17 00:00:00 2001 From: Daku Date: Mon, 24 Feb 2014 01:50:31 +0000 Subject: [PATCH] have query use EXISTS rather than IN preferably we would have a table with image tag counts, but this works for now --- ext/tag_categories/main.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ext/tag_categories/main.php b/ext/tag_categories/main.php index 285a18e8..80f62e88 100644 --- a/ext/tag_categories/main.php +++ b/ext/tag_categories/main.php @@ -51,7 +51,7 @@ class TagCategories extends Extension { public function onSearchTermParse(SearchTermParseEvent $event) { $matches = array(); - if(preg_match("/^(.+)tags([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])([0-9]+)$/", $event->term, $matches)) { + if(preg_match("/^(.+)tags([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])([0-9]+)$/i", $event->term, $matches)) { global $database; $type = $matches[1]; $cmp = ltrim($matches[2], ":") ?: "="; @@ -59,15 +59,15 @@ class TagCategories extends Extension { $types = $database->get_col('SELECT category FROM image_tag_categories'); if(in_array($type, $types)) { - $event->add_querylet(new Querylet("images.id IN ( - SELECT * FROM ( - SELECT it.image_id - FROM image_tags it - LEFT JOIN tags t ON it.tag_id = t.id - GROUP BY image_id - HAVING SUM(CASE WHEN t.tag LIKE '$type:%' THEN 1 ELSE 0 END) $cmp $count - ) AS subquery - )")); + $event->add_querylet( + new Querylet("EXISTS ( + SELECT 1 + FROM image_tags it + LEFT JOIN tags t ON it.tag_id = t.id + WHERE images.id = it.image_id + GROUP BY image_id + HAVING SUM(CASE WHEN t.tag LIKE '$type:%' THEN 1 ELSE 0 END) $cmp $count + )")); } } }