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