From abf86271ff36e37c23338b712960dc4a56b7836b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Saquetim?= <1108771+megothss@users.noreply.github.com> Date: Wed, 27 Mar 2024 16:32:45 -0300 Subject: [PATCH] DEV: Extract the query code from CategoryList.find_relevant_topics into a separate method (#26390) ## Why this change? The previous implementation of the method generated the query to find the relevant topics and iterated over the results, processing them. This behavior made difficult reusing or changing the query logic in classes extending `CategoryList`. This commit extracts the query logic into another method called `relevant_topics_query ` which can be reused or overwritten in descendant classes. --- app/models/category_list.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/category_list.rb b/app/models/category_list.rb index 30fa828abbf..0e5828b3daf 100644 --- a/app/models/category_list.rb +++ b/app/models/category_list.rb @@ -70,7 +70,7 @@ class CategoryList private - def find_relevant_topics + def relevant_topics_query @all_topics = Topic .secured(@guardian) @@ -104,10 +104,12 @@ class CategoryList end @all_topics = TopicQuery.remove_muted_tags(@all_topics, @guardian.user).includes(:last_poster) + end + def find_relevant_topics featured_topics_by_category_id = Hash.new { |h, k| h[k] = [] } - @all_topics.each do |t| + relevant_topics_query.each do |t| # hint for the serializer t.include_last_poster = true t.dismissed = dismissed_topic?(t)