Skip to content

Commit

Permalink
discussion entries: simplify create_participants transaction
Browse files Browse the repository at this point in the history
fixes CNVS-12567, CNVS-14786

test plan:
  * create discussion entries in a topic with multiple participants
  * verify that topic unread counts and message unread statuses
      are maintained correctly
  * if possible, load test simultaneous entry creation
      and verify that no deadlock occurs

Change-Id: I9c5ce430d9c7914648e5920bd317949fe15f22f3
Reviewed-on: https://gerrit.instructure.com/39318
Reviewed-by: Cody Cutrer <[email protected]>
Tested-by: Jenkins <[email protected]>
Product-Review: Braden Anderson <[email protected]>
QA-Review: August Thornton <[email protected]>
  • Loading branch information
bluej100 authored and codekitchen committed Aug 15, 2014
1 parent f7ca3ef commit 4b1a018
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/models/discussion_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ def context_module_action
end

def create_participants
subscription_hold = self.discussion_topic.subscription_hold(self.user, nil, nil)
transaction do
scope = DiscussionTopicParticipant.where(:discussion_topic_id => self.discussion_topic_id)
scope = scope.where("user_id<>?", self.user) if self.user
Expand All @@ -365,13 +366,13 @@ def create_participants

topic_participant = self.discussion_topic.discussion_topic_participants.find_by_user_id(self.user.id)
if topic_participant.blank?
new_count = self.discussion_topic.unread_count(self.user) - 1
new_count = self.discussion_topic.default_unread_count - 1
topic_participant = self.discussion_topic.discussion_topic_participants.create(:user => self.user,
:unread_entry_count => new_count,
:workflow_state => "unread",
:subscribed => self.discussion_topic.subscribed?(self.user))
end
self.discussion_topic.subscribe(self.user) unless self.discussion_topic.subscription_hold(self.user, nil, nil)
self.discussion_topic.subscribe(self.user) unless subscription_hold
end
end
end
Expand Down

0 comments on commit 4b1a018

Please sign in to comment.