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
2bb94ff7
Commit
2bb94ff7
authored
Jun 03, 2018
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Eliminate N+1 queries for CI job artifacts in /api/projects/:id/pipelines/:pipeline_id/jobs
parent
c26cbfcd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
0 deletions
+18
-0
changelogs/unreleased/sh-fix-pipeline-jobs-nplus-one.yml
changelogs/unreleased/sh-fix-pipeline-jobs-nplus-one.yml
+5
-0
lib/api/jobs.rb
lib/api/jobs.rb
+1
-0
spec/requests/api/jobs_spec.rb
spec/requests/api/jobs_spec.rb
+12
-0
No files found.
changelogs/unreleased/sh-fix-pipeline-jobs-nplus-one.yml
0 → 100644
View file @
2bb94ff7
---
title
:
Eliminate N+1 queries for CI job artifacts in /api/prjoects/:id/pipelines/:pipeline_id/jobs
merge_request
:
author
:
type
:
performance
lib/api/jobs.rb
View file @
2bb94ff7
...
...
@@ -54,6 +54,7 @@ module API
pipeline
=
user_project
.
pipelines
.
find
(
params
[
:pipeline_id
])
builds
=
pipeline
.
builds
builds
=
filter_builds
(
builds
,
params
[
:scope
])
builds
=
builds
.
preload
(
:job_artifacts_archive
)
present
paginate
(
builds
),
with:
Entities
::
Job
end
...
...
spec/requests/api/jobs_spec.rb
View file @
2bb94ff7
...
...
@@ -177,6 +177,18 @@ describe API::Jobs do
json_response
.
each
{
|
job
|
expect
(
job
[
'pipeline'
][
'id'
]).
to
eq
(
pipeline
.
id
)
}
end
end
it
'avoids N+1 queries'
do
control_count
=
ActiveRecord
::
QueryRecorder
.
new
(
skip_cached:
false
)
do
get
api
(
"/projects/
#{
project
.
id
}
/pipelines/
#{
pipeline
.
id
}
/jobs"
,
api_user
),
query
end
.
count
3
.
times
{
create
(
:ci_build
,
:artifacts
,
pipeline:
pipeline
)
}
expect
do
get
api
(
"/projects/
#{
project
.
id
}
/pipelines/
#{
pipeline
.
id
}
/jobs"
,
api_user
),
query
end
.
not_to
exceed_all_query_limit
(
control_count
)
end
end
context
'unauthorized user'
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