Commit 46a0de8d authored by Igor's avatar Igor Committed by Stan Hu

Preload authors on commits and blame pages

Currently the full potential of lazy_author
is not used
Let's try and use lazy_author&.itself instead
of lazy_author.__sync to load authors in batches
parent c07d0e81
...@@ -72,6 +72,8 @@ class Projects::CommitsController < Projects::ApplicationController ...@@ -72,6 +72,8 @@ class Projects::CommitsController < Projects::ApplicationController
@repository.commits(@ref, path: @path, limit: @limit, offset: @offset) @repository.commits(@ref, path: @path, limit: @limit, offset: @offset)
end end
@commits.each(&:lazy_author) # preload authors
@commits = @commits.with_latest_pipeline(@ref) @commits = @commits.with_latest_pipeline(@ref)
@commits = set_commits_for_rendering(@commits) @commits = set_commits_for_rendering(@commits)
end end
......
...@@ -56,16 +56,6 @@ module AvatarsHelper ...@@ -56,16 +56,6 @@ module AvatarsHelper
})) }))
end end
def user_avatar_url_for(only_path: true, **options)
if options[:url]
options[:url]
elsif options[:user]
avatar_icon_for_user(options[:user], options[:size], only_path: only_path)
else
avatar_icon_for_email(options[:user_email], options[:size], only_path: only_path)
end
end
def user_avatar_without_link(options = {}) def user_avatar_without_link(options = {})
avatar_size = options[:size] || 16 avatar_size = options[:size] || 16
user_name = options[:user].try(:name) || options[:user_name] user_name = options[:user].try(:name) || options[:user_name]
...@@ -111,6 +101,19 @@ module AvatarsHelper ...@@ -111,6 +101,19 @@ module AvatarsHelper
private private
def user_avatar_url_for(only_path: true, **options)
return options[:url] if options[:url]
email = options[:user_email]
user = options.key?(:user) ? options[:user] : User.find_by_any_email(email)
if user
avatar_icon_for_user(user, options[:size], only_path: only_path)
else
gravatar_icon(email, options[:size])
end
end
def source_icon(source, options = {}) def source_icon(source, options = {})
avatar_url = source.try(:avatar_url) avatar_url = source.try(:avatar_url)
......
...@@ -257,10 +257,9 @@ class Commit ...@@ -257,10 +257,9 @@ class Commit
end end
def author def author
# We use __sync so that we get the actual objects back (including an actual strong_memoize(:author) do
# nil), instead of a wrapper, as returning a wrapped nil breaks a lot of lazy_author&.itself
# code. end
lazy_author.__sync
end end
request_cache(:author) { author_email.downcase } request_cache(:author) { author_email.downcase }
......
---
title: Optimize SQL requests for BlameController and CommitsController
merge_request: 18342
author:
type: performance
...@@ -17,6 +17,7 @@ module Gitlab ...@@ -17,6 +17,7 @@ module Gitlab
i = 0 i = 0
blame.each do |commit, line| blame.each do |commit, line|
commit = Commit.new(commit, project) commit = Commit.new(commit, project)
commit.lazy_author # preload author
sha = commit.sha sha = commit.sha
if prev_sha != sha if prev_sha != sha
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment