From 91dcc56fb3f3c9bf2e1378a576f7984007fd8880 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 10 Sep 2014 17:10:57 +1000 Subject: [PATCH] Revert "PERF: avoid OR in complex query" This reverts commit a8dc6daa38f1fdc09e477222451bd5a2612b59f5. --- app/models/topic_tracking_state.rb | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/app/models/topic_tracking_state.rb b/app/models/topic_tracking_state.rb index 83caf3b84a1..2ed1bf5f0de 100644 --- a/app/models/topic_tracking_state.rb +++ b/app/models/topic_tracking_state.rb @@ -144,7 +144,7 @@ class TopicTrackingState LEFT JOIN categories c ON c.id = topics.category_id WHERE u.id IN (:user_ids) AND topics.archetype <> 'private_message' AND - (**COND**) AND + ((#{unread}) OR (#{new})) AND (topics.visible OR u.admin OR u.moderator) AND topics.deleted_at IS NULL AND ( category_id IS NULL OR NOT c.read_restricted OR category_id IN ( @@ -163,19 +163,11 @@ SQL if topic_id sql << " AND topics.id = :topic_id" end - sql << " ORDER BY topics.bumped_at DESC LIMIT 250" - - sql = wrap(sql.sub("**COND**", new), "A") << " UNION ALL " << wrap(sql.sub("**COND**", unread),"B") + sql << " ORDER BY topics.bumped_at DESC LIMIT 500" SqlBuilder.new(sql) .map_exec(TopicTrackingState, user_ids: user_ids, topic_id: topic_id) end - private - - def self.wrap(query, name) - "SELECT * FROM (#{query}) #{name}" - end - end