mirror of
https://github.com/discourse/discourse.git
synced 2025-07-05 00:32:27 +00:00
FIX: mutex to avoid race condition with double notify
This commit is contained in:
parent
81c18fc0bd
commit
a7e65d98a9
@ -1,3 +1,5 @@
|
|||||||
|
require_dependency 'distributed_mutex'
|
||||||
|
|
||||||
class PostAlerter
|
class PostAlerter
|
||||||
|
|
||||||
def self.post_created(post)
|
def self.post_created(post)
|
||||||
@ -222,6 +224,7 @@ class PostAlerter
|
|||||||
|
|
||||||
notification_type = Notification.types[:group_message_summary]
|
notification_type = Notification.types[:group_message_summary]
|
||||||
|
|
||||||
|
DistributedMutex.synchronize("group_message_notify_#{user.id}") do
|
||||||
Notification.where(notification_type: notification_type, user_id: user.id).each do |n|
|
Notification.where(notification_type: notification_type, user_id: user.id).each do |n|
|
||||||
n.destroy if n.data_hash[:group_id] == stat[:group_id]
|
n.destroy if n.data_hash[:group_id] == stat[:group_id]
|
||||||
end
|
end
|
||||||
@ -236,6 +239,7 @@ class PostAlerter
|
|||||||
username: user.username_lower
|
username: user.username_lower
|
||||||
}.to_json
|
}.to_json
|
||||||
)
|
)
|
||||||
|
end
|
||||||
|
|
||||||
# TODO decide if it makes sense to also publish a desktop notification
|
# TODO decide if it makes sense to also publish a desktop notification
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user