fix materialized views through pgbouncer

i.e. don't use find_each with an order outside of a transaction

test plan:
 * through pgbouncer
 * with jobs running
 * create a new discussion topic, and access it
 * it should not seem to hang

Change-Id: I1f83497fe482246520c0858f638218e895dfb9c7
Reviewed-on: https://gerrit.instructure.com/23077
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Brian Palmer <brianp@instructure.com>
Product-Review: Cody Cutrer <cody@instructure.com>
QA-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
Cody Cutrer 2013-08-06 14:30:17 -06:00
parent 5c8ea0cc73
commit c3c60e8684
1 changed files with 13 additions and 11 deletions

View File

@ -98,17 +98,19 @@ class DiscussionTopic::MaterializedView < ActiveRecord::Base
entry_lookup = {}
view = []
user_ids = Set.new
discussion_entries = self.discussion_topic.discussion_entries
discussion_entries.find_each do |entry|
json = discussion_entry_api_json([entry], discussion_topic.context, nil, nil, []).first
entry_lookup[entry.id] = json
user_ids << entry.user_id
user_ids << entry.editor_id if entry.editor_id
if parent = entry_lookup[entry.parent_id]
parent['replies'] ||= []
parent['replies'] << json
else
view << json
Shackles.activate(:slave) do
discussion_entries = self.discussion_topic.discussion_entries
discussion_entries.find_each do |entry|
json = discussion_entry_api_json([entry], discussion_topic.context, nil, nil, []).first
entry_lookup[entry.id] = json
user_ids << entry.user_id
user_ids << entry.editor_id if entry.editor_id
if parent = entry_lookup[entry.parent_id]
parent['replies'] ||= []
parent['replies'] << json
else
view << json
end
end
end
return view.to_json, user_ids.to_a, entry_lookup.keys