From bc73cf692d25fc5224d2061149ec55c1c94f258b Mon Sep 17 00:00:00 2001 From: Kevin McConnell Date: Thu, 20 Nov 2025 09:20:48 +0000 Subject: [PATCH] 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. --- app/models/notifier.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/notifier.rb b/app/models/notifier.rb index 81e69ce07..24c1b3b4e 100644 --- a/app/models/notifier.rb +++ b/app/models/notifier.rb @@ -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