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