Look at whether upsert is possible for create/update namespace commit email
<!--IssueSummary start--> <details> <summary> Everyone can contribute. [Help move this issue forward](https://handbook.gitlab.com/handbook/marketing/developer-relations/contributor-success/community-contributors-workflows/#contributor-links) while earning points, leveling up and collecting rewards. </summary> - [Close this issue](https://contributors.gitlab.com/manage-issue?action=close&projectId=278964&issueIid=415214) </details> <!--IssueSummary end--> The following discussion from !108236 should be addressed: - [ ] @terrichu started a [discussion](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/108236#note_1422610687): (+3 comments) > **suggestion (non-blocking):** upsert could be useful to avoid a race condition (edge case), something like this (not sure if this is fully working) > > ```suggestion:-8+0 > if email_id.nil? > remove_namespace_commit_email(existing_namespace_commit_email) > else > namespace_commit_email = ::Users::NamespaceCommitEmail.new( > user: target_user, > namespace: namespace, > email: email > ) > namespace_commit_email.validate! > > ::Users::NamespaceCommitEmail.upsert(namespace_commit_email.attributes, returning: ??, unique_by: ??) > end > ```
issue