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
a51a599a
Commit
a51a599a
authored
Jul 17, 2020
by
Terri Chu
Committed by
Toon Claes
Jul 17, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix explore projects controller n+1 bullet report
parent
8c6cc649
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
1 deletion
+35
-1
app/controllers/explore/projects_controller.rb
app/controllers/explore/projects_controller.rb
+1
-1
changelogs/unreleased/tchu-fix-explore-projects-controller-n-1.yml
...s/unreleased/tchu-fix-explore-projects-controller-n-1.yml
+5
-0
spec/controllers/explore/projects_controller_spec.rb
spec/controllers/explore/projects_controller_spec.rb
+29
-0
No files found.
app/controllers/explore/projects_controller.rb
View file @
a51a599a
...
...
@@ -80,7 +80,7 @@ class Explore::ProjectsController < Explore::ApplicationController
# rubocop: disable CodeReuse/ActiveRecord
def
preload_associations
(
projects
)
projects
.
includes
(
:route
,
:creator
,
:group
,
namespace:
[
:route
,
:owner
])
projects
.
includes
(
:route
,
:creator
,
:group
,
:project_feature
,
namespace:
[
:route
,
:owner
])
end
# rubocop: enable CodeReuse/ActiveRecord
...
...
changelogs/unreleased/tchu-fix-explore-projects-controller-n-1.yml
0 → 100644
View file @
a51a599a
---
title
:
Fix N+1 issue in Explore Projects controller.
merge_request
:
36874
author
:
type
:
performance
spec/controllers/explore/projects_controller_spec.rb
View file @
a51a599a
...
...
@@ -138,6 +138,33 @@ RSpec.describe Explore::ProjectsController do
end
end
shared_examples
'avoids N+1 queries'
do
[
:index
,
:trending
,
:starred
].
each
do
|
endpoint
|
describe
"GET
#{
endpoint
}
"
do
render_views
# some N+1 queries still exist
it
'avoids N+1 queries'
do
projects
=
create_list
(
:project
,
3
,
:repository
,
:public
)
projects
.
each
do
|
project
|
pipeline
=
create
(
:ci_pipeline
,
:success
,
project:
project
,
sha:
project
.
commit
.
id
)
create
(
:commit_status
,
:success
,
pipeline:
pipeline
,
ref:
pipeline
.
ref
)
end
control
=
ActiveRecord
::
QueryRecorder
.
new
{
get
endpoint
}
new_projects
=
create_list
(
:project
,
2
,
:repository
,
:public
)
new_projects
.
each
do
|
project
|
pipeline
=
create
(
:ci_pipeline
,
:success
,
project:
project
,
sha:
project
.
commit
.
id
)
create
(
:commit_status
,
:success
,
pipeline:
pipeline
,
ref:
pipeline
.
ref
)
end
expect
{
get
endpoint
}.
not_to
exceed_query_limit
(
control
).
with_threshold
(
8
)
end
end
end
end
context
'when user is signed in'
do
let
(
:user
)
{
create
(
:user
)
}
...
...
@@ -147,6 +174,7 @@ RSpec.describe Explore::ProjectsController do
include_examples
'explore projects'
include_examples
"blocks high page numbers"
include_examples
'avoids N+1 queries'
context
'user preference sorting'
do
let
(
:project
)
{
create
(
:project
)
}
...
...
@@ -160,6 +188,7 @@ RSpec.describe Explore::ProjectsController do
context
'when user is not signed in'
do
include_examples
'explore projects'
include_examples
"blocks high page numbers"
include_examples
'avoids N+1 queries'
context
'user preference sorting'
do
let
(
:project
)
{
create
(
:project
)
}
...
...
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