Skip to content

Commit 3de1309

Browse files
committed
Only call after_update_* when something changed
1 parent a271760 commit 3de1309

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

app/models/ext_management_system.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,12 @@ def edit_with_params(params, endpoints, authentications)
193193
endpoints_changed ||= ems.endpoints.any?(&:changed?)
194194
authentications_changed ||= ems.authentications.any?(&:changed?)
195195

196-
after_update_endpoints if endpoints_changed
197-
after_update_authentication if authentications_changed
198-
199196
ems.provider.save! if ems.provider.present? && ems.provider.changed?
200197
ems.save!
201198
end
199+
200+
after_update_endpoints if endpoints_changed
201+
after_update_authentication if authentications_changed
202202
end
203203
end
204204

@@ -920,14 +920,14 @@ def stop_event_monitor_queue
920920
end
921921

922922
def stop_event_monitor_queue_on_change
923-
if event_monitor_class && !new_record? && default_endpoint.changed.include_any?("hostname", "ipaddress")
923+
if event_monitor_class && !new_record?
924924
_log.info("EMS: [#{name}], Hostname or IP address has changed, stopping Event Monitor. It will be restarted by the WorkerMonitor.")
925925
stop_event_monitor_queue
926926
end
927927
end
928928

929929
def stop_event_monitor_queue_on_credential_change
930-
if event_monitor_class && !new_record? && default_authentication&.changed?
930+
if event_monitor_class && !new_record?
931931
_log.info("EMS: [#{name}], Credentials have changed, stopping Event Monitor. It will be restarted by the WorkerMonitor.")
932932
stop_event_monitor_queue
933933
end

app/models/mixins/authentication_mixin.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def update_authentication(data, options = {})
186186
# Invoke before callback
187187
before_update_authentication if self.respond_to?(:before_update_authentication) && options[:save]
188188

189-
data.each_pair do |type, value|
189+
authentication_changes = data.each_pair.map do |type, value|
190190
cred = authentication_type(type)
191191
current = {:new => nil, :old => nil}
192192

@@ -243,11 +243,17 @@ def update_authentication(data, options = {})
243243
cred.auth_key = value[:auth_key]
244244
cred.service_account = value[:service_account].presence
245245

246+
changes = {type => cred.changes} if cred.changed?
247+
246248
cred.save if options[:save] && id
247-
end
249+
250+
changes
251+
end.compact
252+
253+
return if authentication_changes.blank? || !options[:save]
248254

249255
# Invoke callback
250-
after_update_authentication if self.respond_to?(:after_update_authentication) && options[:save]
256+
after_update_authentication if respond_to?(:after_update_authentication)
251257
end
252258

253259
def authentication_type(type)

0 commit comments

Comments
 (0)