From a70153106ab9c47f298e187b2c293a4878871c70 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Mon, 25 Jun 2018 15:32:54 +0200 Subject: [PATCH] Fixed race condition: Scheduler job pushes outdated data to the client. --- .../concerns/checks_latest_change_observed.rb | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/app/models/concerns/checks_latest_change_observed.rb b/app/models/concerns/checks_latest_change_observed.rb index 09bad426f..0fd2d9d80 100644 --- a/app/models/concerns/checks_latest_change_observed.rb +++ b/app/models/concerns/checks_latest_change_observed.rb @@ -3,19 +3,11 @@ module ChecksLatestChangeObserved extend ActiveSupport::Concern included do - after_create :latest_change_set_from_observer - after_update :latest_change_set_from_observer - after_touch :latest_change_set_from_observer - after_destroy :latest_change_set_from_observer_destroy + after_commit :latest_change_set_from_observer end def latest_change_set_from_observer - self.class.latest_change_set(updated_at) - true - end - - def latest_change_set_from_observer_destroy - self.class.latest_change_set(nil) - true + latest_change = destroyed? ? nil : updated_at + self.class.latest_change_set(latest_change) end end