aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2012-06-07 15:26:53 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2012-06-07 15:26:53 +0100
commitd67ea28693088e4d7039069b52541777eb7aa989 (patch)
treef7e1cbc8391dc825eea5cdd8c53b40edf08a7204 /lib
parent456459820f46dc2423a62ee2f9384a51e4f76a8e (diff)
Updated DuringRunner to cache calls to the calendar more.
Diffstat (limited to 'lib')
-rw-r--r--lib/mauve/notification.rb16
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/mauve/notification.rb b/lib/mauve/notification.rb
index 57d82d2..745660a 100644
--- a/lib/mauve/notification.rb
+++ b/lib/mauve/notification.rb
@@ -124,14 +124,20 @@ module Mauve
def no_one_in(people_list)
return true unless Configuration.current.people[people_list].respond_to?(:people)
+ @test_time = @time if @test_time.nil?
+
#
- # Cache the results to prevent hitting the calendar too many times.
+ # This is cached by itself, since calendar calls are rounded to the
+ # nearest minute. However this cache expires with the during runner,
+ # which isn't so insane..
#
- @no_one_in_cache ||= Hash.new
+ test_time = @test_time - @test_time.sec
- return @no_one_in_cache[people_list] if @no_one_in_cache.has_key?(people_list)
+ @no_one_in_cache ||= Hash.new{|h,k| h[k] = Hash.new}
- @no_one_in_cache[people_list] = Configuration.current.people[people_list].people(@time).empty?
+ return @no_one_in_cache[people_list][test_time] if @no_one_in_cache[people_list].has_key?(test_time)
+
+ @no_one_in_cache[people_list][test_time] = Configuration.current.people[people_list].people(test_time).empty?
end
# Returns true if the current hour is in the list of hours given.
@@ -248,7 +254,7 @@ module Mauve
@during = nil
@every = nil
@level = nil
- end
+ end
# @return [String]
def to_s