mirror of
https://github.com/discourse/discourse.git
synced 2025-06-22 19:21:34 +08:00
PERF: fixes N+1 for automation plugin (#32810)
- Add a safeguard until we implement pagination for the index, it ensures we won't try to load more than 500 automations ever. - Includes the fields of the automation so we don't have an N+1 and also filter them in ruby land instead of doing two additional queries - Ensures a field object in the field serializer is capable to find the loaded automation associated to it instead of trying to reload it - Includes pending_automations to avoid an N+1
This commit is contained in:
@ -7,7 +7,8 @@ module DiscourseAutomation
|
||||
has_many :fields,
|
||||
class_name: "DiscourseAutomation::Field",
|
||||
dependent: :delete_all,
|
||||
foreign_key: "automation_id"
|
||||
foreign_key: "automation_id",
|
||||
inverse_of: :automation
|
||||
has_many :pending_automations,
|
||||
class_name: "DiscourseAutomation::PendingAutomation",
|
||||
dependent: :delete_all,
|
||||
@ -28,6 +29,16 @@ module DiscourseAutomation
|
||||
|
||||
attr_accessor :running_in_background
|
||||
|
||||
def trigger=(new_trigger)
|
||||
@triggerable = nil
|
||||
super
|
||||
end
|
||||
|
||||
def script=(new_script)
|
||||
@scriptable = nil
|
||||
super
|
||||
end
|
||||
|
||||
def running_in_background!
|
||||
@running_in_background = true
|
||||
end
|
||||
|
Reference in New Issue
Block a user