summaryrefslogtreecommitdiff
path: root/app/models/commit.rb
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2018-11-14 18:42:36 +0000
committerNick Thomas <nick@gitlab.com>2018-11-19 12:45:07 +0000
commit59c4fb4ecb3aa81ea73a5fe75528ef969c28fa9d (patch)
treec4fb7f51773be8c797b05809081ba50d61e3a338 /app/models/commit.rb
parent3eb366722e32d878d56ed09a5fa596b777fccef5 (diff)
downloadgitlab-ce-59c4fb4ecb3aa81ea73a5fe75528ef969c28fa9d.tar.gz
Match users better by their private commit email
Private commit emails were introduced in !22560, but some parts of GitLab were not updated to take account of them. This commit adds support in places that were missed.
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