From 59c4fb4ecb3aa81ea73a5fe75528ef969c28fa9d Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Wed, 14 Nov 2018 18:42:36 +0000 Subject: 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. --- app/models/commit.rb | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) (limited to 'app/models/commit.rb') 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 -- cgit v1.2.1