Skip to content

Commit 365ddcb

Browse files
committed
discussion entries: simplify create_participants transaction
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 <cody@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> Product-Review: Braden Anderson <braden@instructure.com> QA-Review: August Thornton <august@instructure.com>
1 parent 987da0a commit 365ddcb

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

app/models/discussion_entry.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ def context_module_action
355355
end
356356

357357
def create_participants
358+
subscription_hold = self.discussion_topic.subscription_hold(self.user, nil, nil)
358359
transaction do
359360
scope = DiscussionTopicParticipant.where(:discussion_topic_id => self.discussion_topic_id)
360361
scope = scope.where("user_id<>?", self.user) if self.user
@@ -365,13 +366,13 @@ def create_participants
365366

366367
topic_participant = self.discussion_topic.discussion_topic_participants.find_by_user_id(self.user.id)
367368
if topic_participant.blank?
368-
new_count = self.discussion_topic.unread_count(self.user) - 1
369+
new_count = self.discussion_topic.default_unread_count - 1
369370
topic_participant = self.discussion_topic.discussion_topic_participants.create(:user => self.user,
370371
:unread_entry_count => new_count,
371372
:workflow_state => "unread",
372373
:subscribed => self.discussion_topic.subscribed?(self.user))
373374
end
374-
self.discussion_topic.subscribe(self.user) unless self.discussion_topic.subscription_hold(self.user, nil, nil)
375+
self.discussion_topic.subscribe(self.user) unless subscription_hold
375376
end
376377
end
377378
end

0 commit comments

Comments
 (0)