Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
2d144568
Commit
2d144568
authored
Apr 12, 2021
by
Dmitry Gruzd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix N+1 for searching commits
parent
d2be5844
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
1 deletion
+19
-1
app/controllers/concerns/renders_commits.rb
app/controllers/concerns/renders_commits.rb
+2
-1
changelogs/unreleased/327006-fix-search-commits-n-plus-1.yml
changelogs/unreleased/327006-fix-search-commits-n-plus-1.yml
+5
-0
spec/controllers/concerns/renders_commits_spec.rb
spec/controllers/concerns/renders_commits_spec.rb
+12
-0
No files found.
app/controllers/concerns/renders_commits.rb
View file @
2d144568
...
...
@@ -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
...
...
changelogs/unreleased/327006-fix-search-commits-n-plus-1.yml
0 → 100644
View file @
2d144568
---
title
:
Fix N+1 for searching commits
merge_request
:
58867
author
:
type
:
performance
spec/controllers/concerns/renders_commits_spec.rb
View file @
2d144568
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment