Cache BroadcastMessage.current for 5 minutes. Fixes #12770

This commit is contained in:
Josh Frye 2016-01-27 12:20:17 -05:00
parent dec2151718
commit d8a292d907
1 changed files with 3 additions and 1 deletions

View File

@ -26,7 +26,9 @@ class BroadcastMessage < ActiveRecord::Base
default_value_for :font, '#FFFFFF'
def self.current
where("ends_at > :now AND starts_at <= :now", now: Time.zone.now).last
Rails.cache.fetch("broadcast_message_current", expires_in: 5.minutes) do
where("ends_at > :now AND starts_at <= :now", now: Time.zone.now).last
end
end
def active?