FEATURE: allow plugins to preload custom data on search (#11518)

This commit allows discourse-assign plugin to show assigned users on
search result topic list.
This commit is contained in:
Arpit Jalan 2020-12-17 21:59:10 +05:30 committed by GitHub
parent 4b1d98e878
commit 29c7655221
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,6 +7,16 @@ class Search
cattr_accessor :preloaded_topic_custom_fields cattr_accessor :preloaded_topic_custom_fields
self.preloaded_topic_custom_fields = Set.new self.preloaded_topic_custom_fields = Set.new
def self.on_preload(&blk)
(@preload ||= Set.new) << blk
end
def self.preload(results, object)
if @preload
@preload.each { |preload| preload.call(results, object) }
end
end
def self.per_facet def self.per_facet
5 5
end end
@ -164,7 +174,7 @@ class Search
end end
attr_accessor :term attr_accessor :term
attr_reader :clean_term attr_reader :clean_term, :guardian
def initialize(term, opts = nil) def initialize(term, opts = nil)
@opts = opts || {} @opts = opts || {}
@ -282,6 +292,8 @@ class Search
Topic.preload_custom_fields(topics, preloaded_topic_custom_fields) Topic.preload_custom_fields(topics, preloaded_topic_custom_fields)
end end
Search.preload(@results, self)
@results @results
end end