mirror of
https://github.com/discourse/discourse.git
synced 2025-06-23 03:11:31 +08:00
PERF: prevents N+1 on last_updated_by (#32817)
This commit is contained in:
@ -8,7 +8,7 @@ module DiscourseAutomation
|
||||
automations =
|
||||
DiscourseAutomation::Automation
|
||||
.strict_loading
|
||||
.includes(:fields, :pending_automations)
|
||||
.includes(:fields, :pending_automations, :last_updated_by)
|
||||
.order(:name)
|
||||
.limit(500)
|
||||
.all
|
||||
@ -26,7 +26,11 @@ module DiscourseAutomation
|
||||
|
||||
def show
|
||||
automation =
|
||||
DiscourseAutomation::Automation.includes(:fields, :pending_automations).find(params[:id])
|
||||
DiscourseAutomation::Automation.includes(
|
||||
:fields,
|
||||
:pending_automations,
|
||||
:last_updated_by,
|
||||
).find(params[:id])
|
||||
render_serialized_automation(automation)
|
||||
end
|
||||
|
||||
|
@ -4,6 +4,8 @@ module DiscourseAutomation
|
||||
class Automation < ActiveRecord::Base
|
||||
self.table_name = "discourse_automation_automations"
|
||||
|
||||
belongs_to :last_updated_by, class_name: "User", foreign_key: "last_updated_by_id"
|
||||
|
||||
has_many :fields,
|
||||
class_name: "DiscourseAutomation::Field",
|
||||
dependent: :delete_all,
|
||||
@ -17,7 +19,6 @@ module DiscourseAutomation
|
||||
class_name: "DiscourseAutomation::PendingPm",
|
||||
dependent: :delete_all,
|
||||
foreign_key: "automation_id"
|
||||
|
||||
has_many :stats, class_name: "DiscourseAutomation::Stat", dependent: :delete_all
|
||||
|
||||
validates :script, presence: true
|
||||
|
@ -14,10 +14,7 @@ module DiscourseAutomation
|
||||
attribute :stats
|
||||
|
||||
def last_updated_by
|
||||
BasicUserSerializer.new(
|
||||
User.find_by(id: object.last_updated_by_id) || Discourse.system_user,
|
||||
root: false,
|
||||
).as_json
|
||||
BasicUserSerializer.new(object.last_updated_by || Discourse.system_user, root: false).as_json
|
||||
end
|
||||
|
||||
def include_next_pending_automation_at?
|
||||
|
Reference in New Issue
Block a user