mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 11:11:13 +08:00
DEV: Allow specifying a condition when preloading topics for topic list (#32101)
Currently when using `register_topic_preloader_associations`, we are not able to specify a condition that is evaluated at runtime. This commit allows specifying a condition and also keeps backward compatibility. ``` register_topic_preloader_associations(:linked_topic) { true } register_topic_preloader_associations({ first_post: [uploads] }) ```
This commit is contained in:
@ -1347,6 +1347,24 @@ class Plugin::Instance
|
||||
end
|
||||
end
|
||||
|
||||
# This method allows plugins to preload topic associations when loading topics
|
||||
# that make use of topic_list.
|
||||
#
|
||||
# @param fields [Symbol, Array<Symbol>, Hash] The topic associations to preload.
|
||||
#
|
||||
# @example
|
||||
# register_topic_preloader_associations(:first_post)
|
||||
# register_topic_preloader_associations([:first_post, :topic_embeds])
|
||||
# register_topic_preloader_associations({ first_post: :uploads })
|
||||
# register_topic_preloader_associations({ first_post: :uploads }) do
|
||||
# SiteSetting.some_setting_enabled?
|
||||
# end
|
||||
#
|
||||
# @return [void]
|
||||
def register_topic_preloader_associations(fields, &condition)
|
||||
DiscoursePluginRegistry.register_topic_preloader_association({ fields:, condition: }, self)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def self.js_path
|
||||
@ -1441,10 +1459,6 @@ class Plugin::Instance
|
||||
reloadable_patch { NewPostManager.add_plugin_payload_attribute(attribute_name) }
|
||||
end
|
||||
|
||||
def register_topic_preloader_associations(fields)
|
||||
DiscoursePluginRegistry.register_topic_preloader_association(fields, self)
|
||||
end
|
||||
|
||||
##
|
||||
# Allows plugins to preload topic associations when loading categories with topics.
|
||||
#
|
||||
|
Reference in New Issue
Block a user