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
fb950c9a
Commit
fb950c9a
authored
Jul 01, 2021
by
lauraMon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds spec for N+1
parent
21608c77
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
13 deletions
+30
-13
app/graphql/types/ci/stage_type.rb
app/graphql/types/ci/stage_type.rb
+7
-3
spec/requests/api/graphql/ci/jobs_spec.rb
spec/requests/api/graphql/ci/jobs_spec.rb
+23
-10
No files found.
app/graphql/types/ci/stage_type.rb
View file @
fb950c9a
...
...
@@ -52,9 +52,13 @@ module Types
# rubocop: disable CodeReuse/ActiveRecord
def
jobs_for_pipeline
(
pipeline
,
stage_ids
,
include_needs
)
results
=
pipeline
.
latest_statuses
.
where
(
stage_id:
stage_ids
)
results
=
results
.
preload
(
:project
)
results
=
results
.
preload
(
:needs
)
if
include_needs
builds_results
=
pipeline
.
latest_builds
.
where
(
stage_id:
stage_ids
).
preload
(
:job_artifacts
,
:project
)
bridges_results
=
pipeline
.
bridges
.
where
(
stage_id:
stage_ids
).
preload
(
:project
)
builds_results
=
builds_results
.
preload
(
:needs
)
if
include_needs
bridges_results
=
bridges_results
.
preload
(
:needs
)
if
include_needs
commit_status_results
=
pipeline
.
latest_statuses
.
where
(
stage_id:
stage_ids
)
results
=
builds_results
|
bridges_results
|
commit_status_results
results
.
group_by
(
&
:stage_id
)
end
...
...
spec/requests/api/graphql/ci/jobs_spec.rb
View file @
fb950c9a
...
...
@@ -117,14 +117,19 @@ RSpec.describe 'Query.project.pipeline' do
)
end
it
'avoids N+1 queries'
do
control_count
=
ActiveRecord
::
QueryRecorder
.
new
do
post_graphql
(
query
,
current_user:
user
,
variables:
first_n
.
with
(
1
))
it
'does not generate N+1 queries'
,
:request_store
,
:use_sql_query_cache
do
post_graphql
(
query
,
current_user:
user
)
control
=
ActiveRecord
::
QueryRecorder
.
new
(
skip_cached:
false
)
do
post_graphql
(
query
,
current_user:
user
)
end
create
(
:ci_build
,
name:
'test-a'
,
pipeline:
pipeline
)
create
(
:ci_build
,
name:
'test-b'
,
pipeline:
pipeline
)
expect
do
post_graphql
(
query
,
current_user:
user
,
variables:
first_n
.
with
(
3
)
)
end
.
not_to
exceed_
query_limit
(
control_count
)
post_graphql
(
query
,
current_user:
user
)
end
.
not_to
exceed_
all_query_limit
(
control
)
end
end
end
...
...
@@ -137,6 +142,10 @@ RSpec.describe 'Query.project.pipeline' do
query {
project(fullPath: "#{project.full_path}") {
pipeline(iid: "#{pipeline.iid}") {
stages {
nodes {
groups{
nodes {
jobs {
nodes {
artifacts {
...
...
@@ -149,6 +158,10 @@ RSpec.describe 'Query.project.pipeline' do
}
}
}
}
}
}
}
)
end
...
...
@@ -158,7 +171,7 @@ RSpec.describe 'Query.project.pipeline' do
post_graphql
(
query
,
current_user:
user
)
job_data
=
graphql_data
.
dig
(
'project'
,
'pipeline'
,
'jobs'
,
'nodes'
).
first
job_data
=
graphql_data
_at
(
:project
,
:pipeline
,
:stages
,
:nodes
,
:groups
,
:nodes
,
:jobs
,
:nodes
).
first
expect
(
job_data
.
dig
(
'artifacts'
,
'nodes'
).
count
).
to
be
(
2
)
end
end
...
...
@@ -169,7 +182,7 @@ RSpec.describe 'Query.project.pipeline' do
post_graphql
(
query
,
current_user:
user
)
job_data
=
graphql_data
.
dig
(
'project'
,
'pipeline'
,
'jobs'
,
'nodes'
).
first
job_data
=
graphql_data
_at
(
:project
,
:pipeline
,
:stages
,
:nodes
,
:groups
,
:nodes
,
:jobs
,
:nodes
).
first
expect
(
job_data
[
'artifacts'
]).
to
be_nil
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