lib/rufus/scheduler/cronline.rb in rufus-scheduler-3.1.10 vs lib/rufus/scheduler/cronline.rb in rufus-scheduler-3.2.0

- old
+ new

@@ -40,12 +40,12 @@ attr_reader :seconds attr_reader :minutes attr_reader :hours attr_reader :days attr_reader :months + #attr_reader :monthdays # reader defined below attr_reader :weekdays - attr_reader :monthdays attr_reader :timezone def initialize(line) fail ArgumentError.new( @@ -221,10 +221,14 @@ d = sec - prev [ sec, d < delta ? d : delta ] }[1] end + # Caching facility. Currently only used for brute frequencies. + # + @cache = {}; class << self; attr_reader :cache; end + # Returns the shortest delta between two potential occurences of the # schedule described by this cronline. # # . # @@ -237,20 +241,17 @@ # of a whole year and keeps the shortest. # # Of course, this method can get VERY slow if you call on it a second- # based cronline... # - # Since it's a rarely used method, I haven't taken the time to make it - # smarter/faster. - # - # One obvious improvement would be to cache the result once computed... - # - # See https://github.com/jmettraux/rufus-scheduler/issues/89 - # for a discussion about this method. - # def brute_frequency + key = "brute_frequency:#{@original}" + + delta = self.class.cache[key] + return delta if delta + delta = 366 * DAY_S t0 = previous_time(Time.local(2000, 1, 1)) loop do @@ -266,11 +267,11 @@ break if t1.year >= 2001 t0 = t1 end - delta + self.class.cache[key] = delta end def next_second(time) secs = toa(@seconds) @@ -375,10 +376,10 @@ def parse_range(item, min, max) return %w[ L ] if item == 'L' - item = '*' + item if item.match(/^\//) + item = '*' + item if item[0, 1] == '/' m = item.match(RANGE_REGEX) fail ArgumentError.new( "cannot parse #{item.inspect}"