diff options
author | Patrick J Cherry <patrick@bytemark.co.uk> | 2012-03-22 10:07:17 +0000 |
---|---|---|
committer | Patrick J Cherry <patrick@bytemark.co.uk> | 2012-03-22 10:07:17 +0000 |
commit | 53c5b4412c46dd289eeac08a9a4768aaf9d069ff (patch) | |
tree | 05af339adb24a8886ad1ddee38fd5ac9cd7bc082 | |
parent | 495780ac5299b26009bea86319f44301bd301db1 (diff) |
Improved caching, I think.
Updated changelog.
-rw-r--r-- | debian/changelog | 7 | ||||
-rw-r--r-- | lib/mauve/alert.rb | 48 |
2 files changed, 31 insertions, 24 deletions
diff --git a/debian/changelog b/debian/changelog index d1856db..fc69f21 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +mauvealert (3.7.4) stable; urgency=low + + * Possible improvements in alert group caching, in an attempt to fix + slowness in the interface. + + -- Patrick J Cherry <patrick@bytemark.co.uk> Thu, 22 Mar 2012 10:06:07 +0000 + mauvealert (3.7.3) stable; urgency=low * Added destroy command to XMPP interface. diff --git a/lib/mauve/alert.rb b/lib/mauve/alert.rb index ace20cc..d867ccd 100644 --- a/lib/mauve/alert.rb +++ b/lib/mauve/alert.rb @@ -105,7 +105,6 @@ module Mauve before :valid?, :do_set_timestamps before :save, :do_sanitize_html before :save, :take_copy_of_changes - before :save, :update_alert_group_cache after :save, :notify_if_needed after :destroy, :destroy_associations @@ -141,28 +140,6 @@ module Mauve end end - def update_alert_group_cache - if @alert_group.nil? or self.updated_at < @alert_group.last_resolved_at - # - # Find the alert group - # - alert_group = AlertGroup.matches(self).first - else - alert_group = @alert_group - end - - # - # Cache the name - # - if alert_group.is_a?(AlertGroup) - attribute_set("cached_alert_group", alert_group.name) - else - attribute_set("cached_alert_group", nil) - end - - true - end - # # @return [Mauve::AlertGroup] The first matching AlertGroup for this alert def alert_group @@ -175,7 +152,7 @@ module Mauve # If we've not found the alert group by name, or the object hasn't been # saved since the alert group was last resolved, look for it again. # - @alert_group = AlertGroup.matches(self).first if @alert_group.nil? or self.updated_at < (Time.now - 1800) + @alert_group = AlertGroup.matches(self).first if @alert_group.nil? @alert_group end @@ -392,6 +369,13 @@ module Mauve self.will_unacknowledge_at = ack_until self.update_type = "acknowledged" + # + # Re-cache the alert group. + # + @alert_group = nil + self.cached_alert_group = nil + self.cached_alert_group = self.alert_group.name + unless save logger.error("Couldn't save #{self}") false @@ -440,6 +424,13 @@ module Mauve if self.will_unacknowledge_at and self.will_unacknowledge_at <= Time.now self.will_unacknowledge_at = postpone_until end + + # + # Re-cache the alert group. + # + @alert_group = nil + self.cached_alert_group = nil + self.cached_alert_group = self.alert_group.name logger.info("Postponing raise of #{self} until #{postpone_until} as it was last updated in a prior run of Mauve.") else @@ -451,6 +442,11 @@ module Mauve self.cleared_at = nil # Don't clear will_clear_at self.update_type = "raised" if self.update_type.nil? or self.update_type != "changed" or self.original_attributes[Alert.properties[:update_type]] == "cleared" + + # + # Cache the alert group, but only if not already set. + # + self.cached_alert_group = self.alert_group.name if self.cached_alert_group.nil? end unless save @@ -487,6 +483,10 @@ module Mauve self.cleared_at = at if self.cleared_at.nil? self.will_clear_at = nil self.update_type = "cleared" + # + # Un-cache the alert group + # + self.cached_alert_group = nil end if save |