diff --git a/app/models/topic_list.rb b/app/models/topic_list.rb index 6c2fbc776ca..9578eb11310 100644 --- a/app/models/topic_list.rb +++ b/app/models/topic_list.rb @@ -77,7 +77,7 @@ class TopicList def categories @categories ||= - topics.map { |t| [t.category&.parent_category, t.category] }.uniq.flatten.compact + topics.map { |t| [t.category&.parent_category, t.category] }.flatten.uniq.compact end def load_topics diff --git a/lib/topic_view.rb b/lib/topic_view.rb index d52c9f0c37b..1b8ab6eb140 100644 --- a/lib/topic_view.rb +++ b/lib/topic_view.rb @@ -727,9 +727,9 @@ class TopicView end def categories - categories = [category, category&.parent_category] - categories += suggested_topics.categories if suggested_topics - categories.compact.uniq + @categories ||= [category&.parent_category, category, suggested_topics&.categories].flatten + .uniq + .compact end protected