mirror of
https://github.com/discourse/discourse.git
synced 2025-03-06 03:09:43 +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
|
||||
|
||||
def self.post_created(post)
|
||||
@ -222,20 +224,22 @@ class PostAlerter
|
||||
|
||||
notification_type = Notification.types[:group_message_summary]
|
||||
|
||||
Notification.where(notification_type: notification_type, user_id: user.id).each do |n|
|
||||
n.destroy if n.data_hash[:group_id] == stat[:group_id]
|
||||
end
|
||||
DistributedMutex.synchronize("group_message_notify_#{user.id}") do
|
||||
Notification.where(notification_type: notification_type, user_id: user.id).each do |n|
|
||||
n.destroy if n.data_hash[:group_id] == stat[:group_id]
|
||||
end
|
||||
|
||||
Notification.create(
|
||||
notification_type: notification_type,
|
||||
user_id: user.id,
|
||||
data: {
|
||||
group_id: stat[:group_id],
|
||||
group_name: stat[:group_name],
|
||||
inbox_count: stat[:inbox_count],
|
||||
username: user.username_lower
|
||||
}.to_json
|
||||
)
|
||||
Notification.create(
|
||||
notification_type: notification_type,
|
||||
user_id: user.id,
|
||||
data: {
|
||||
group_id: stat[:group_id],
|
||||
group_name: stat[:group_name],
|
||||
inbox_count: stat[:inbox_count],
|
||||
username: user.username_lower
|
||||
}.to_json
|
||||
)
|
||||
end
|
||||
|
||||
# TODO decide if it makes sense to also publish a desktop notification
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user