DEV: Serialize categories in topic lists (#23597)

At this moment, this feature is under a site setting named
lazy_load_categories.

In the future, categories will no longer be preloaded through site data.
This commit add information about categories in topic list and ensures
that data is used to display topic list items.

Parent categories are serialized too because they are necessary to
render {{category-link}}.
This commit is contained in:
Bianca Nenciu
2023-10-17 19:06:01 +03:00
committed by GitHub
parent 5e6c63901f
commit c95ffb98ef
6 changed files with 89 additions and 1 deletions

View File

@@ -76,6 +76,10 @@ class TopicList
@topics ||= load_topics
end
def categories
@categories ||= topics.map { |t| [t.category, t.category.parent_category] }.uniq.flatten.compact
end
def load_topics
@topics = @topics_input
@@ -128,7 +132,12 @@ class TopicList
ft.topic_list = self
end
topic_preloader_associations = [:image_upload, { topic_thumbnails: :optimized_image }]
topic_preloader_associations = [
:image_upload,
{ topic_thumbnails: :optimized_image },
{ category: :parent_category },
]
topic_preloader_associations.concat(DiscoursePluginRegistry.topic_preloader_associations.to_a)
ActiveRecord::Associations::Preloader.new(