Commit 2d144568 authored by Dmitry Gruzd's avatar Dmitry Gruzd

Fix N+1 for searching commits

parent d2be5844
......@@ -17,12 +17,13 @@ module RendersCommits
def set_commits_for_rendering(commits, commits_count: nil)
@total_commit_count = commits_count || commits.size
limited, @hidden_commit_count = limited_commits(commits, @total_commit_count)
commits.each(&:lazy_author) # preload authors
prepare_commits_for_rendering(limited)
end
# rubocop: enable Gitlab/ModuleWithInstanceVariables
def prepare_commits_for_rendering(commits)
commits.each(&:lazy_author) # preload commits' authors
Banzai::CommitRenderer.render(commits, @project, current_user) # rubocop:disable Gitlab/ModuleWithInstanceVariables
commits
......
---
title: Fix N+1 for searching commits
merge_request: 58867
author:
type: performance
......@@ -57,4 +57,16 @@ RSpec.describe RendersCommits do
end.not_to exceed_all_query_limit(control_count)
end
end
describe '.prepare_commits_for_rendering' do
it 'avoids N+1' do
control = ActiveRecord::QueryRecorder.new do
subject.prepare_commits_for_rendering(merge_request.commits.take(1))
end
expect do
subject.prepare_commits_for_rendering(merge_request.commits)
end.not_to exceed_all_query_limit(control.count)
end
end
end
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