mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
FIX: Adding a user to a group twice under concurrency
This prevents an error from being raised / logged.
This commit is contained in:
@ -321,8 +321,14 @@ class GroupsController < ApplicationController
|
|||||||
))
|
))
|
||||||
else
|
else
|
||||||
users.each do |user|
|
users.each do |user|
|
||||||
|
begin
|
||||||
group.add(user)
|
group.add(user)
|
||||||
GroupActionLogger.new(current_user, group).log_add_user_to_group(user)
|
GroupActionLogger.new(current_user, group).log_add_user_to_group(user)
|
||||||
|
rescue ActiveRecord::RecordNotUnique
|
||||||
|
# Under concurrency, we might attempt to insert two records quickly and hit a DB
|
||||||
|
# constraint. In this case we can safely ignore the error and act as if the user
|
||||||
|
# was added to the group.
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
render json: success_json.merge!(
|
render json: success_json.merge!(
|
||||||
|
Reference in New Issue
Block a user