Process notification recipients in consistent order

We've seen some cases of deadlock when processing notifications, because
locks are gathered on the users in different orders. Let's try sticking
to a consistent order instead, which should cause the jobs to serialize
rather than deadlock.
This commit is contained in:
Kevin McConnell
2025-11-20 09:20:48 +00:00
parent f6d1dee9b4
commit bc73cf692d
+2 -1
View File
@@ -14,7 +14,8 @@ class Notifier
def notify
if should_notify?
recipients.map do |recipient|
# Processing recipients in order avoids deadlocks if notifications overlap.
recipients.sort_by(&:id).map do |recipient|
Notification.create! user: recipient, source: source, creator: creator
end
end