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
f6f3d8b8
Commit
f6f3d8b8
authored
Apr 19, 2021
by
Vitali Tatarintev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Preload Ci::Runner tags to prevent N+1 queries
parent
2b4b7852
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
5 deletions
+34
-5
app/controllers/projects/settings/ci_cd_controller.rb
app/controllers/projects/settings/ci_cd_controller.rb
+3
-2
spec/controllers/projects/settings/ci_cd_controller_spec.rb
spec/controllers/projects/settings/ci_cd_controller_spec.rb
+31
-3
No files found.
app/controllers/projects/settings/ci_cd_controller.rb
View file @
f6f3d8b8
...
...
@@ -119,12 +119,13 @@ module Projects
.
assignable_for
(
project
)
.
ordered
.
page
(
params
[
:specific_page
]).
per
(
NUMBER_OF_RUNNERS_PER_PAGE
)
.
with_tags
@shared_runners
=
::
Ci
::
Runner
.
instance_type
.
active
@shared_runners
=
::
Ci
::
Runner
.
instance_type
.
active
.
with_tags
@shared_runners_count
=
@shared_runners
.
count
(
:all
)
@group_runners
=
::
Ci
::
Runner
.
belonging_to_parent_group_of_project
(
@project
.
id
)
@group_runners
=
::
Ci
::
Runner
.
belonging_to_parent_group_of_project
(
@project
.
id
)
.
with_tags
end
def
define_ci_variables
...
...
spec/controllers/projects/settings/ci_cd_controller_spec.rb
View file @
f6f3d8b8
...
...
@@ -14,6 +14,10 @@ RSpec.describe Projects::Settings::CiCdController do
end
describe
'GET show'
do
let
(
:parent_group
)
{
create
(
:group
)
}
let
(
:group
)
{
create
(
:group
,
parent:
parent_group
)
}
let
(
:other_project
)
{
create
(
:project
,
group:
group
)
}
it
'renders show with 200 status code'
do
get
:show
,
params:
{
namespace_id:
project
.
namespace
,
project_id:
project
}
...
...
@@ -22,10 +26,7 @@ RSpec.describe Projects::Settings::CiCdController do
end
context
'with group runners'
do
let
(
:parent_group
)
{
create
(
:group
)
}
let
(
:group
)
{
create
(
:group
,
parent:
parent_group
)
}
let
(
:group_runner
)
{
create
(
:ci_runner
,
:group
,
groups:
[
group
])
}
let
(
:other_project
)
{
create
(
:project
,
group:
group
)
}
let!
(
:project_runner
)
{
create
(
:ci_runner
,
:project
,
projects:
[
other_project
])
}
let!
(
:shared_runner
)
{
create
(
:ci_runner
,
:instance
)
}
...
...
@@ -37,6 +38,33 @@ RSpec.describe Projects::Settings::CiCdController do
expect
(
assigns
(
:assignable_runners
)).
to
contain_exactly
(
project_runner
)
end
end
context
'prevents N+1 queries for tags'
do
render_views
def
show
get
:show
,
params:
{
namespace_id:
project
.
namespace
,
project_id:
project
}
end
it
'has the same number of queries with one tag or with many tags'
,
:request_store
do
group
.
add_maintainer
(
user
)
show
# warmup
# with one tag
create
(
:ci_runner
,
:instance
,
tag_list:
%w(shared_runner)
)
create
(
:ci_runner
,
:project
,
projects:
[
other_project
],
tag_list:
%w(project_runner)
)
create
(
:ci_runner
,
:group
,
groups:
[
group
],
tag_list:
%w(group_runner)
)
control
=
ActiveRecord
::
QueryRecorder
.
new
{
show
}
# with several tags
create
(
:ci_runner
,
:instance
,
tag_list:
%w(shared_runner tag2 tag3)
)
create
(
:ci_runner
,
:project
,
projects:
[
other_project
],
tag_list:
%w(project_runner tag2 tag3)
)
create
(
:ci_runner
,
:group
,
groups:
[
group
],
tag_list:
%w(group_runner tag2 tag3)
)
expect
{
show
}.
not_to
exceed_query_limit
(
control
)
end
end
end
describe
'#reset_cache'
do
...
...
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