aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2012-12-05 12:33:59 +0000
committerPatrick J Cherry <patrick@bytemark.co.uk>2012-12-05 12:33:59 +0000
commit96771ec4af3c90f39081ae13321e17096c43eaa2 (patch)
tree1c2190b5da50218fbbfdf24541b0dac5bae93992 /lib/mauve
parentdebded63c18e4cb01faa8306c727c0c0472852bc (diff)
Make sure that the datamapper query is evaluated when clearing all alerts.
Diffstat (limited to 'lib/mauve')
-rw-r--r--lib/mauve/alert.rb15
1 files changed, 9 insertions, 6 deletions
diff --git a/lib/mauve/alert.rb b/lib/mauve/alert.rb
index 82f9e91..3307b59 100644
--- a/lib/mauve/alert.rb
+++ b/lib/mauve/alert.rb
@@ -902,12 +902,15 @@ module Mauve
#
if update.replace
alert_ids_mentioned = update.alert.map { |alert| alert.id }
- logger.info "Replacing all alerts from #{update.source} except "+alert_ids_mentioned.join(",")
- all(:source => update.source,
- :alert_id.not => alert_ids_mentioned,
- :cleared_at => nil
- ).each do |alert_db|
- alert_db.clear!
+ logger.info "Replacing all alerts from #{update.source}"+(alert_ids_mentioned.count > 0 ? " except "+alert_ids_mentioned.join(",") : "")
+ #
+ # The to_a is used here to make sure datamapper runs the query now,
+ # rather than at some point in the future.
+ #
+ Alert.all(:source => update.source,
+ :alert_id.not => alert_ids_mentioned
+ ).to_a.each do |alert_db|
+ alert_db.clear! unless alert_db.cleared?
end
end