mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 18:43:37 +08:00
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:
parent
4b1d98e878
commit
29c7655221
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user