A platform for community discussion. Free, open, simple.
FIX: Prevent UniqueViolation exceptions when syncing group mentions (#12543)
Daniel Waterworth330c831ba4fb
diff --git a/app/services/post_alerter.rb b/app/services/post_alerter.rbindex fc6c74bed88..c062bb6b448 100644--- a/app/services/post_alerter.rb+++ b/app/services/post_alerter.rb@@ -156,9 +156,20 @@ class PostAlerterGroupMention.where(post_id: post.id).destroy_allreturn if mentioned_groups.blank?- mentioned_groups.each do |group|- GroupMention.create(post_id: post.id, group_id: group.id)- end+ now = Time.zone.now++ # insert_all instead of insert_all! since multiple post_alert jobs might be+ # running concurrently+ GroupMention.insert_all(+ mentioned_groups.map do |group|+ {+ post_id: post.id,+ group_id: group.id,+ created_at: now,+ updated_at: now,+ }+ end+ )enddef unread_posts(user, topic)