fix N+1 queries in AccountsController
fixes CNVS-15391 test plan: accounts api sanity check Change-Id: I6c218ea92aec63bd3ef52072b5e9b687aeb0c886 Reviewed-on: https://gerrit.instructure.com/40840 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Jon Willesen <jonw@instructure.com> QA-Review: Clare Strong <clare@instructure.com> Product-Review: Jeremy Stanley <jeremy@instructure.com>
This commit is contained in:
parent
c02192c1f7
commit
4219b7192a
|
@ -116,6 +116,7 @@ class AccountsController < ApplicationController
|
|||
else
|
||||
@accounts = []
|
||||
end
|
||||
Account.send(:preload_associations, @accounts, [:root_account])
|
||||
render :json => @accounts.map { |a| account_json(a, @current_user, session, params[:includes] || []) }
|
||||
end
|
||||
end
|
||||
|
@ -177,6 +178,7 @@ class AccountsController < ApplicationController
|
|||
@accounts = Api.paginate(@accounts, self, api_v1_sub_accounts_url,
|
||||
:total_entries => recursive ? nil : @accounts.count)
|
||||
|
||||
Account.send(:preload_associations, @accounts, [:root_account, :parent_account])
|
||||
render :json => @accounts.map { |a| account_json(a, @current_user, session, []) }
|
||||
end
|
||||
|
||||
|
@ -280,6 +282,7 @@ class AccountsController < ApplicationController
|
|||
|
||||
@courses = Api.paginate(@courses, self, api_v1_account_courses_url)
|
||||
|
||||
Course.send(:preload_associations, @courses, [:account, :root_account])
|
||||
render :json => @courses.map { |c| course_json(c, @current_user, session, [], nil) }
|
||||
end
|
||||
|
||||
|
|
|
@ -498,9 +498,11 @@ class Account < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def default_storage_quota
|
||||
read_attribute(:default_storage_quota) ||
|
||||
(self.parent_account.default_storage_quota rescue nil) ||
|
||||
Setting.get('account_default_quota', 500.megabytes.to_s).to_i
|
||||
Rails.cache.fetch(['default_storage_quota', self].cache_key) do
|
||||
read_attribute(:default_storage_quota) ||
|
||||
(self.parent_account.default_storage_quota rescue nil) ||
|
||||
Setting.get('account_default_quota', 500.megabytes.to_s).to_i
|
||||
end
|
||||
end
|
||||
|
||||
def default_storage_quota_mb
|
||||
|
|
Loading…
Reference in New Issue