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
7598b7bd
Commit
7598b7bd
authored
Mar 29, 2021
by
Alex Buijs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Preload job_artifacts_archives for API endpoint
In order to prevent n+1 queries
parent
b121d0ea
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
72 additions
and
1 deletion
+72
-1
app/models/ci/processable.rb
app/models/ci/processable.rb
+7
-1
app/presenters/ci/build_runner_presenter.rb
app/presenters/ci/build_runner_presenter.rb
+12
-0
config/feature_flags/development/preload_associations_jobs_request_api_endpoint.yml
...opment/preload_associations_jobs_request_api_endpoint.yml
+8
-0
spec/requests/api/ci/runner/jobs_request_post_spec.rb
spec/requests/api/ci/runner/jobs_request_post_spec.rb
+30
-0
spec/support/matchers/exceed_query_limit.rb
spec/support/matchers/exceed_query_limit.rb
+5
-0
spec/support_specs/matchers/exceed_query_limit_helpers_spec.rb
...support_specs/matchers/exceed_query_limit_helpers_spec.rb
+10
-0
No files found.
app/models/ci/processable.rb
View file @
7598b7bd
...
...
@@ -165,7 +165,13 @@ module Ci
end
def
all_dependencies
dependencies
.
all
if
Feature
.
enabled?
(
:preload_associations_jobs_request_api_endpoint
,
project
,
default_enabled: :yaml
)
strong_memoize
(
:all_dependencies
)
do
dependencies
.
all
end
else
dependencies
.
all
end
end
private
...
...
app/presenters/ci/build_runner_presenter.rb
View file @
7598b7bd
...
...
@@ -55,6 +55,18 @@ module Ci
specs
end
# rubocop: disable CodeReuse/ActiveRecord
def
all_dependencies
dependencies
=
super
if
Feature
.
enabled?
(
:preload_associations_jobs_request_api_endpoint
,
project
,
default_enabled: :yaml
)
ActiveRecord
::
Associations
::
Preloader
.
new
.
preload
(
dependencies
,
:job_artifacts_archive
)
end
dependencies
end
# rubocop: enable CodeReuse/ActiveRecord
private
def
create_archive
(
artifacts
)
...
...
config/feature_flags/development/preload_associations_jobs_request_api_endpoint.yml
0 → 100644
View file @
7598b7bd
---
name
:
preload_associations_jobs_request_api_endpoint
introduced_by_url
:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/57694
rollout_issue_url
:
https://gitlab.com/gitlab-org/gitlab/-/issues/326477
milestone
:
"
13.11"
type
:
development
group
:
group::continuous integration
default_enabled
:
true
spec/requests/api/ci/runner/jobs_request_post_spec.rb
View file @
7598b7bd
...
...
@@ -490,6 +490,36 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do
{
'id'
=>
job
.
id
,
'name'
=>
job
.
name
,
'token'
=>
job
.
token
},
{
'id'
=>
job2
.
id
,
'name'
=>
job2
.
name
,
'token'
=>
job2
.
token
})
end
describe
'preloading job_artifacts_archive'
do
context
'when the feature flag is disabled'
do
before
do
stub_feature_flags
(
preload_associations_jobs_request_api_endpoint:
false
)
end
it
'queries the ci_job_artifacts table multiple times'
do
expect
{
request_job
}.
to
exceed_all_query_limit
(
1
).
for_model
(
::
Ci
::
JobArtifact
)
end
it
'queries the ci_builds table more than five times'
do
expect
{
request_job
}.
to
exceed_all_query_limit
(
5
).
for_model
(
::
Ci
::
Build
)
end
end
context
'when the feature flag is enabled'
do
before
do
stub_feature_flags
(
preload_associations_jobs_request_api_endpoint:
true
)
end
it
'queries the ci_job_artifacts table once only'
do
expect
{
request_job
}.
not_to
exceed_all_query_limit
(
1
).
for_model
(
::
Ci
::
JobArtifact
)
end
it
'queries the ci_builds table five times'
do
expect
{
request_job
}.
not_to
exceed_all_query_limit
(
5
).
for_model
(
::
Ci
::
Build
)
end
end
end
end
context
'when pipeline have jobs with artifacts'
do
...
...
spec/support/matchers/exceed_query_limit.rb
View file @
7598b7bd
...
...
@@ -20,6 +20,11 @@ module ExceedQueryLimitHelpers
self
end
def
for_model
(
model
)
table
=
model
.
table_name
if
model
<
ActiveRecord
::
Base
for_query
(
/(FROM|UPDATE|INSERT INTO|DELETE FROM)\s+"
#{
table
}
"/
)
end
def
show_common_queries
@show_common_queries
=
true
self
...
...
spec/support_specs/matchers/exceed_query_limit_helpers_spec.rb
View file @
7598b7bd
...
...
@@ -225,6 +225,16 @@ RSpec.describe ExceedQueryLimitHelpers do
expect
(
test_matcher
.
actual_count
).
to
eq
(
2
)
end
it
'can filter specific models'
do
test_matcher
=
TestMatcher
.
new
.
for_model
(
TestQueries
)
test_matcher
.
verify_count
do
TestQueries
.
first
TestQueries
.
connection
.
execute
(
'select 1'
)
end
expect
(
test_matcher
.
actual_count
).
to
eq
(
1
)
end
it
'can ignore specific queries'
do
test_matcher
=
TestMatcher
.
new
.
ignoring
(
/foobar/
)
test_matcher
.
verify_count
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