Commit e0df60c2 authored by Stan Hu's avatar Stan Hu

Merge branch 'id-blame-controller-performance' into 'master'

Optimize SQL requests for BlameController and CommitsController

See merge request gitlab-org/gitlab!18342
parents c07d0e81 46a0de8d
......@@ -72,6 +72,8 @@ class Projects::CommitsController < Projects::ApplicationController
@repository.commits(@ref, path: @path, limit: @limit, offset: @offset)
end
@commits.each(&:lazy_author) # preload authors
@commits = @commits.with_latest_pipeline(@ref)
@commits = set_commits_for_rendering(@commits)
end
......
......@@ -56,16 +56,6 @@ module AvatarsHelper
}))
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 = {})
avatar_size = options[:size] || 16
user_name = options[:user].try(:name) || options[:user_name]
......@@ -111,6 +101,19 @@ module AvatarsHelper
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 = {})
avatar_url = source.try(:avatar_url)
......
......@@ -257,10 +257,9 @@ class Commit
end
def author
# 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
strong_memoize(:author) do
lazy_author&.itself
end
end
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
i = 0
blame.each do |commit, line|
commit = Commit.new(commit, project)
commit.lazy_author # preload author
sha = commit.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