summaryrefslogtreecommitdiff
path: root/app/models/commit.rb
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2018-11-19 16:53:14 +0000
committerDouwe Maan <douwe@gitlab.com>2018-11-19 16:53:14 +0000
commitaf1ed0e2bbabb72aff521aa2d67a4325dd94f711 (patch)
tree143fac4538c3b20d5479c1f4096f52be26c870a8 /app/models/commit.rb
parentd5f08596305a7643d884e57ffc0375c6a5a7dbcb (diff)
parent59c4fb4ecb3aa81ea73a5fe75528ef969c28fa9d (diff)
downloadgitlab-ce-af1ed0e2bbabb72aff521aa2d67a4325dd94f711.tar.gz
Merge branch '54046-fix-by-any-email-for-private-commit-emails' into 'master'
Match users better by their private commit email Closes #54046 See merge request gitlab-org/gitlab-ce!23080
Diffstat (limited to 'app/models/commit.rb')
-rw-r--r--app/models/commit.rb25
1 files changed, 7 insertions, 18 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 9dd0cbacd9e..546fcc54a15 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -230,24 +230,13 @@ class Commit
def lazy_author
BatchLoader.for(author_email.downcase).batch do |emails, loader|
- # A Hash that maps user Emails to the corresponding User objects. The
- # Emails at this point are the _primary_ Emails of the Users.
- users_for_emails = User
- .by_any_email(emails)
- .each_with_object({}) { |user, hash| hash[user.email] = user }
-
- users_for_ids = users_for_emails
- .values
- .each_with_object({}) { |user, hash| hash[user.id] = user }
-
- # Some commits may have used an alternative Email address. In this case we
- # need to query the "emails" table to map those addresses to User objects.
- Email
- .where(email: emails - users_for_emails.keys)
- .pluck(:email, :user_id)
- .each { |(email, id)| users_for_emails[email] = users_for_ids[id] }
-
- users_for_emails.each { |email, user| loader.call(email, user) }
+ users = User.by_any_email(emails).includes(:emails)
+
+ emails.each do |email|
+ user = users.find { |u| u.any_email?(email) }
+
+ loader.call(email, user)
+ end
end
end