diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2018-05-18 17:25:24 +0100 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2018-05-18 17:25:24 +0100 |
commit | 7f0f8594d3e5cbee41771c476e3b7496946db300 (patch) | |
tree | 1981c15675409386908b3b05d4f1aa75b1755957 /app/models/commit.rb | |
parent | 068186555cb85e85bbfe04afe858fb3eb4801207 (diff) | |
parent | 8bacfbd1cc4f6c3678d50dd516df2b59eb0c8864 (diff) | |
download | gitlab-ce-5845-extract-ee-environments-files.tar.gz |
Merge branch 'master' into 5845-extract-ee-environments-files5845-extract-ee-environments-files
* master: (69 commits)
Calculating repository checksums executed by Gitaly
Resolve "Expand API: Render an arbitrary Markdown document"
Update EE > CE downgrade service removal steps
Make stores export a createStore() which can be used in tests
Simplify pattern lexeme fabrication and matcher
Simplify untrusted regexp factory method
Fix api_json.log not always reporting the right HTTP status code
Move group lists css from framework/lists.scss to pages/groups.scss
Resolve "Web IDE: Previewing Markdown in Firefox doesn’t show a scroll bar"
Add Keyboard shortcuts for "Kubernetes" and "Environments"
Move API group deletion to Sidekiq
fix typos. add a reference to deliverable and stretch for design artifact
fix / assigne username wrapping problem has been fixed
Memoize Gitlab::Database.version
Conditionally add Gitaly deprecation warnings based on ENV variable
Bring CE-EE parity to app/services/milestones/base_service.rb
Bring CE-EE parity to app/services/lfs/unlock_file_service.rb
Fixes 500 error on /estimate BIG_VALUE
Fix: Use case in-sensitive ordering by name for groups
Fix group lists visual
...
Diffstat (limited to 'app/models/commit.rb')
-rw-r--r-- | app/models/commit.rb | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb index b46f9f34689..56d4c86774e 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -224,8 +224,34 @@ class Commit Gitlab::ClosingIssueExtractor.new(project, current_user).closed_by_message(safe_message) end + 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) } + end + end + def author - User.find_by_any_email(author_email.downcase) + # We use __sync so that we get the actual objects back (including an actual + # nil), instead of a wrapper, as returning a wrapped nil breaks a lot of + # code. + lazy_author.__sync end request_cache(:author) { author_email.downcase } |