diff options
Diffstat (limited to 'app/services/concerns/members/bulk_create_users.rb')
-rw-r--r-- | app/services/concerns/members/bulk_create_users.rb | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/app/services/concerns/members/bulk_create_users.rb b/app/services/concerns/members/bulk_create_users.rb index 9cfef96311e..3f8971dde74 100644 --- a/app/services/concerns/members/bulk_create_users.rb +++ b/app/services/concerns/members/bulk_create_users.rb @@ -47,16 +47,15 @@ module Members end end - if user_ids.present? - # we should handle the idea of existing members where users are passed as users - https://gitlab.com/gitlab-org/gitlab/-/issues/352617 - # the below will automatically discard invalid user_ids - users.concat(User.id_in(user_ids)) + # the below will automatically discard invalid user_ids + users.concat(User.id_in(user_ids)) if user_ids.present? + users.uniq! # de-duplicate just in case as there is no controlling if user records and ids are sent multiple times + + if users.present? # helps not have to perform another query per user id to see if the member exists later on when fetching - existing_members = source.members_and_requesters.where(user_id: user_ids).index_by(&:user_id) # rubocop:disable CodeReuse/ActiveRecord + existing_members = source.members_and_requesters.where(user_id: users).index_by(&:user_id) # rubocop:disable CodeReuse/ActiveRecord end - users.uniq! # de-duplicate just in case as there is no controlling if user records and ids are sent multiple times - [emails, users, existing_members] end end |