mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user