Skip to content

Commit

Permalink
FIX: Serialize parent categories first (discourse#26294)
Browse files Browse the repository at this point in the history
When categories are loaded by the frontend, the parent category is
looked up by ID and the `parentCategory` is set with the result. If the
categories returned are not in order, the parent category may miss.
  • Loading branch information
nbianca authored Mar 21, 2024
1 parent 2129e9e commit a6e0691
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/models/topic_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def topics

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
Expand Down
6 changes: 3 additions & 3 deletions lib/topic_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -727,9 +727,9 @@ def summarizable?
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
Expand Down

0 comments on commit a6e0691

Please sign in to comment.