Skip to content

Commit ffa00a2

Browse files
committed
query the slave for some expensive queries
Change-Id: Ic2716b75551a85fc028fa7ac0673bf5cb01f14d1 Reviewed-on: https://gerrit.instructure.com/13042 Reviewed-by: Zach Wily <zach@instructure.com> Tested-by: Brian Palmer <brianp@instructure.com>
1 parent 0d4e118 commit ffa00a2

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

app/models/attachment.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -572,9 +572,11 @@ def self.get_quota(context)
572572
quota = 0
573573
quota_used = 0
574574
if context
575-
quota = Setting.get_cached('context_default_quota', 50.megabytes.to_s).to_i
576-
quota = context.quota if (context.respond_to?("quota") && context.quota)
577-
quota_used = context.attachments.active.sum('COALESCE(size, 0)', :conditions => { :root_attachment_id => nil }).to_i
575+
ActiveRecord::Base::ConnectionSpecification.with_environment(:slave) do
576+
quota = Setting.get_cached('context_default_quota', 50.megabytes.to_s).to_i
577+
quota = context.quota if (context.respond_to?("quota") && context.quota)
578+
quota_used = context.attachments.active.sum('COALESCE(size, 0)', :conditions => { :root_attachment_id => nil }).to_i
579+
end
578580
end
579581
{:quota => quota, :quota_used => quota_used}
580582
end

lib/summary_message_consolidator.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ def initialize(n=nil)
2626
end
2727

2828
def process
29-
cc_ids = CommunicationChannel.ids_with_pending_delayed_messages
29+
cc_ids = ActiveRecord::Base::ConnectionSpecification.with_environment(:slave) do
30+
CommunicationChannel.ids_with_pending_delayed_messages
31+
end
3032
cc_ids.each do |cc_id|
3133
dm_ids = DelayedMessage.ids_for_messages_with_communication_channel_id(cc_id)
3234
DelayedMessage.update_all({ :batched_at => Time.now.utc, :workflow_state => 'sent', :updated_at => Time.now.utc },

0 commit comments

Comments
 (0)