diff options
author | Patrick J Cherry <patrick@bytemark.co.uk> | 2012-05-09 17:04:39 +0100 |
---|---|---|
committer | Patrick J Cherry <patrick@bytemark.co.uk> | 2012-05-09 17:04:39 +0100 |
commit | 196b337a02f959a431a4bb7c443ed116e4e291f3 (patch) | |
tree | 902d0cc46160b611945dbdd0d0216425234edde4 /lib/mauve | |
parent | bebac3756dd535bf754752a34ab8061098d7b91d (diff) |
DuringRunner#no_one_in now is only evaluated once per instance per people_list
to prevent the calendar getting thrashed.
Diffstat (limited to 'lib/mauve')
-rw-r--r-- | lib/mauve/notification.rb | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/mauve/notification.rb b/lib/mauve/notification.rb index 82da2e8..57d82d2 100644 --- a/lib/mauve/notification.rb +++ b/lib/mauve/notification.rb @@ -115,16 +115,23 @@ module Mauve protected - # Test to see if a people_list is empty. + # Test to see if a people_list is empty. NB this is just evaluated at the + # time that the DuringRunner is set up with. # # @param [String] people_list People list to query # @return [Boolean] # def no_one_in(people_list) return true unless Configuration.current.people[people_list].respond_to?(:people) + + # + # Cache the results to prevent hitting the calendar too many times. + # + @no_one_in_cache ||= Hash.new - @test_time = @time if @test_time.nil? - return Configuration.current.people[people_list].people(@test_time).empty? + return @no_one_in_cache[people_list] if @no_one_in_cache.has_key?(people_list) + + @no_one_in_cache[people_list] = Configuration.current.people[people_list].people(@time).empty? end # Returns true if the current hour is in the list of hours given. @@ -347,6 +354,4 @@ module Mauve end - class NotificationDummy < Struct.new(:during, :every) ; end - end |