From d67ea28693088e4d7039069b52541777eb7aa989 Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Thu, 7 Jun 2012 15:26:53 +0100 Subject: Updated DuringRunner to cache calls to the calendar more. --- lib/mauve/notification.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'lib/mauve/notification.rb') 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 -- cgit v1.2.1