From a6e06915c42747b3b44e9b357ab479853c96ff14 Mon Sep 17 00:00:00 2001 From: Bianca Nenciu Date: Thu, 21 Mar 2024 19:51:41 +0200 Subject: [PATCH] FIX: Serialize parent categories first (#26294) 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. --- app/models/topic_list.rb | 2 +- lib/topic_view.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) 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