diff options
author | Louise Crow <louise.crow@gmail.com> | 2012-10-29 19:44:16 +0000 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2012-10-30 10:12:03 +0000 |
commit | 646fffde374e575ab53cfae78e7a0c521cd90d6f (patch) | |
tree | 3fc54c30fb03ee9c0c41fde8fe52ecbb98db1283 | |
parent | 7cad6d60e25e5d1343b1955fd37785589da6b820 (diff) |
Only get the holidays once per request.
-rw-r--r-- | app/models/holiday.rb | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/app/models/holiday.rb b/app/models/holiday.rb index d2437f438..13258396a 100644 --- a/app/models/holiday.rb +++ b/app/models/holiday.rb @@ -23,11 +23,12 @@ class Holiday < ActiveRecord::Base - def Holiday.weekend_or_holiday?(date) - # TODO only fetch holidays after the start_date - holidays = self.all.collect { |h| h.day }.to_set + def Holiday.holidays + @@holidays ||= self.all.collect { |h| h.day }.to_set + end - date.wday == 0 || date.wday == 6 || holidays.include?(date) + def Holiday.weekend_or_holiday?(date) + date.wday == 0 || date.wday == 6 || Holiday.holidays.include?(date) end def Holiday.due_date_from(start_date, days, type_of_days) |