A platform for community discussion. Free, open, simple.
PERF: Prefer subquery instead of two queries (#25167)
Bianca Nenciube46acce8ff9
diff --git a/app/models/category_list.rb b/app/models/category_list.rbindex 6240256c265..108645b63e9 100644--- a/app/models/category_list.rb+++ b/app/models/category_list.rb@@ -58,10 +58,9 @@ class CategoryListif SiteSetting.fixed_category_positionscategories.order(:position, :id)else- allowed_category_ids = categories.pluck(:id) << nil # `nil` is necessary to include categories without any associated topicscategories.left_outer_joins(:featured_topics)- .where(topics: { category_id: allowed_category_ids })+ .where("topics.category_id IS NULL OR topics.category_id IN (?)", categories.select(:id)).group("categories.id").order("max(topics.bumped_at) DESC NULLS LAST").order("categories.id ASC")