From 79d634a0f842177fe1fe380f38b1a4056b6b8944 Mon Sep 17 00:00:00 2001 From: Nick Cloward Date: Tue, 2 Sep 2014 08:41:01 -0600 Subject: [PATCH] speed up account settings users fixes: CNVS-14742 Preloads admin users communication channels. In role overrides it changes the class call for context to index by context_id. Since we know they should always be accounts. Test Plan: - The initial Account settings page should load quicker. - Full permission regression testing. Change-Id: Iadeb55e3b6163421605d1829fa4789c5e1fe9a7e Reviewed-on: https://gerrit.instructure.com/40360 Reviewed-by: Cody Cutrer Tested-by: Jenkins QA-Review: August Thornton QA-Review: Jeremy Putnam Product-Review: Nick Cloward --- app/controllers/accounts_controller.rb | 2 +- app/models/role_override.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index a6fec21ae2c..aba2a891287 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -483,7 +483,7 @@ class AccountsController < ApplicationController end load_course_right_side @account_users = @account.account_users - AccountUser.send(:preload_associations, @account_users, :user) + AccountUser.send(:preload_associations, @account_users, user: :communication_channels) order_hash = {} @account.available_account_roles.each_with_index do |type, idx| order_hash[type] = idx diff --git a/app/models/role_override.rb b/app/models/role_override.rb index ea0bdcefeb3..b7b139edcf8 100644 --- a/app/models/role_override.rb +++ b/app/models/role_override.rb @@ -867,12 +867,12 @@ class RoleOverride < ActiveRecord::Base overrides = @@role_override_chain[permissionless_key] ||= begin role_context.shard.activate do account_ids = context.account_chain_ids(include_site_admin: true).reverse - overrides = RoleOverride.where(:context_id => account_ids, :enrollment_type => generated_permission[:enrollment_type].to_s).group_by(&:permission) + overrides = RoleOverride.where(:context_id => account_ids, :context_type => 'Account', :enrollment_type => generated_permission[:enrollment_type].to_s).group_by(&:permission) # every context has to be represented so that we can't miss role_context below overrides.each_key do |permission| - overrides_by_account = overrides[permission].index_by { |override| [override.context_id, override.context.class.base_class.name] } + overrides_by_account = overrides[permission].index_by(&:context_id) overrides[permission] = account_ids.map do |account_id| - overrides_by_account[[account_id, 'Account']] || RoleOverride.new { |ro| ro.context_id = account_id; ro.context_type = 'Account' } + overrides_by_account[account_id] || RoleOverride.new { |ro| ro.context_id = account_id; ro.context_type = 'Account' } end end overrides