PERF: Remove N+1 queries on site serializer.
This commit is contained in:
parent
effb7e168b
commit
0fa41a8b38
16
plugin.rb
16
plugin.rb
|
@ -329,11 +329,23 @@ SQL
|
|||
attributes :custom_fields
|
||||
|
||||
def custom_fields
|
||||
object.custom_fields.slice("enable_accepted_answers")
|
||||
object.custom_fields
|
||||
end
|
||||
|
||||
def include_custom_fields?
|
||||
custom_fields.present?
|
||||
SiteSetting.show_filter_by_solved_status && custom_fields.present?
|
||||
end
|
||||
end
|
||||
|
||||
require_dependency 'site'
|
||||
class ::Site
|
||||
alias_method :discourse_categories, :categories
|
||||
|
||||
def categories
|
||||
@categories ||= begin
|
||||
Category.preload_custom_fields(discourse_categories, ["enable_accepted_answers"]) if SiteSetting.show_filter_by_solved_status
|
||||
discourse_categories
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -5,6 +5,10 @@ describe Site do
|
|||
let(:category) { Fabricate(:category) }
|
||||
let(:guardian) { Guardian.new }
|
||||
|
||||
before do
|
||||
SiteSetting.show_filter_by_solved_status = true
|
||||
end
|
||||
|
||||
it "includes `enable_accepted_answers` custom field for categories" do
|
||||
category.custom_fields["enable_accepted_answers"] = true
|
||||
category.save_custom_fields
|
||||
|
|
Loading…
Reference in New Issue