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.
This commit is contained in:
Sérgio Saquetim 2024-03-27 16:32:45 -03:00 committed by GitHub
parent 7b8d60dc20
commit abf86271ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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)