From acee113da41b30c4b616d2f006e9910ec0a13d15 Mon Sep 17 00:00:00 2001 From: Brian Palmer Date: Sun, 26 Aug 2012 14:26:13 -0600 Subject: [PATCH] query the slave for settings and Account#account_users_for Change-Id: Ie423821410080c361d44faa8619ee56321e3bdbd Reviewed-on: https://gerrit.instructure.com/13230 Tested-by: Jenkins Reviewed-by: Zach Wily --- app/models/account.rb | 8 +++++--- app/models/setting.rb | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/models/account.rb b/app/models/account.rb index 41642899ebc..fc03adbaca1 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -545,9 +545,11 @@ class Account < ActiveRecord::Base def account_users_for(user) @account_chain_ids ||= self.account_chain(:include_site_admin => true).map { |a| a.active? ? a.id : nil }.compact @account_users_cache ||= {} - @account_users_cache[user] ||= Shard.partition_by_shard(@account_chain_ids) do |account_chain_ids| - AccountUser.find(:all, :conditions => { :account_id => account_chain_ids, :user_id => user.id }) - end if user + ActiveRecord::Base::ConnectionSpecification.with_environment(:slave) do + @account_users_cache[user] ||= Shard.partition_by_shard(@account_chain_ids) do |account_chain_ids| + AccountUser.find(:all, :conditions => { :account_id => account_chain_ids, :user_id => user.id }) + end if user + end @account_users_cache[user] ||= [] @account_users_cache[user] end diff --git a/app/models/setting.rb b/app/models/setting.rb index f29106cb51a..87d6e9a7467 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -22,7 +22,9 @@ class Setting < ActiveRecord::Base @@cache = {} def self.get(name, default) - Setting.find_or_initialize_by_name(name, :value => default).value + ActiveRecord::Base::ConnectionSpecification.with_environment(:slave) do + Setting.find_or_initialize_by_name(name, :value => default).value + end end def self.set(name, value)