Skip to content

Commit 450e46f

Browse files
committed
preload global announcement account info prior to caching
this avoids repetive queries for site admin Change-Id: I6c7ac3c49f47385167007b92b8e589257250c41f Reviewed-on: https://gerrit.instructure.com/61016 Tested-by: Jenkins Reviewed-by: James Williams <jamesw@instructure.com> QA-Review: August Thornton <august@instructure.com> Product-Review: Cody Cutrer <cody@instructure.com>
1 parent c39499c commit 450e46f

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

app/models/account_notification.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ def validate_dates
3232
def self.for_user_and_account(user, account)
3333
current = self.for_account(account)
3434

35-
ActiveRecord::Associations::Preloader.new(current, [:account, {account_notification_roles: :role}]).run
3635
user_role_ids = {}
3736

3837
current.select! do |announcement|
@@ -99,7 +98,7 @@ def self.for_user_and_account(user, account)
9998

10099
def self.for_account(account)
101100
# Refreshes every 10 minutes at the longest
102-
Rails.cache.fetch(['account_notifications2', account].cache_key, :expires_in => 10.minutes) do
101+
Rails.cache.fetch(['account_notifications3', account].cache_key, expires_in: 10.minutes) do
103102
now = Time.now.utc
104103
# we always check the given account for the flag, even if the announcement is from the site_admin account
105104
# this allows us to make a global announcement that is filtered to only accounts with this flag
@@ -108,7 +107,8 @@ def self.for_account(account)
108107
Shard.partition_by_shard([Account.site_admin, account]) do |accounts|
109108
AccountNotification.where("account_id IN (?) AND start_at <? AND end_at>?", accounts, now, now).
110109
where("required_account_service IS NULL OR required_account_service IN (?)", enabled_flags).
111-
order('start_at DESC').to_a
110+
order('start_at DESC').
111+
preload(:account, account_notification_roles: :role)
112112
end
113113
end
114114
end

0 commit comments

Comments
 (0)