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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
f0d7445b
Commit
f0d7445b
authored
May 24, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce pipeline serialization queries when preloaded
parent
bc9a0e10
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
6 deletions
+9
-6
app/serializers/pipeline_serializer.rb
app/serializers/pipeline_serializer.rb
+5
-3
spec/serializers/pipeline_serializer_spec.rb
spec/serializers/pipeline_serializer_spec.rb
+4
-3
No files found.
app/serializers/pipeline_serializer.rb
View file @
f0d7445b
...
...
@@ -3,8 +3,11 @@ class PipelineSerializer < BaseSerializer
entity
PipelineDetailsEntity
def
represent
(
resource
,
opts
=
{})
if
resource
.
is_a?
(
ActiveRecord
::
Relation
)
if
paginated?
&&
!
resource
.
respond_to?
(
:page
)
raise
Gitlab
::
Serializer
::
Pagination
::
InvalidResourceError
end
if
resource
.
is_a?
(
ActiveRecord
::
Relation
)
resource
=
resource
.
preload
([
:stages
,
:retryable_builds
,
...
...
@@ -18,7 +21,6 @@ class PipelineSerializer < BaseSerializer
end
if
opts
.
delete
(
:preload
)
resource
=
@paginator
.
paginate
(
resource
)
if
paginated?
resource
=
Gitlab
::
Ci
::
Pipeline
::
Preloader
.
preload!
(
resource
)
end
...
...
@@ -35,7 +37,7 @@ class PipelineSerializer < BaseSerializer
def
represent_stages
(
resource
)
return
{}
unless
resource
.
present?
data
=
represent
(
resource
,
{
only:
[{
details:
[
:stages
]
}]
})
data
=
represent
(
resource
,
{
only:
[{
details:
[
:stages
]
}]
,
preload:
true
})
data
.
dig
(
:details
,
:stages
)
||
[]
end
end
spec/serializers/pipeline_serializer_spec.rb
View file @
f0d7445b
...
...
@@ -99,7 +99,8 @@ describe PipelineSerializer do
end
end
context
'number of queries'
do
describe
'number of queries when preloaded'
do
subject
{
serializer
.
represent
(
resource
,
preload:
true
)
}
let
(
:resource
)
{
Ci
::
Pipeline
.
all
}
before
do
...
...
@@ -120,7 +121,7 @@ describe PipelineSerializer do
it
'verifies number of queries'
,
:request_store
do
recorded
=
ActiveRecord
::
QueryRecorder
.
new
{
subject
}
expect
(
recorded
.
count
).
to
be_within
(
1
).
of
(
3
8
)
expect
(
recorded
.
count
).
to
be_within
(
1
).
of
(
3
1
)
expect
(
recorded
.
cached_count
).
to
eq
(
0
)
end
end
...
...
@@ -139,7 +140,7 @@ describe PipelineSerializer do
# pipeline. With the same ref this check is cached but if refs are
# different then there is an extra query per ref
# https://gitlab.com/gitlab-org/gitlab-ce/issues/46368
expect
(
recorded
.
count
).
to
be_within
(
1
).
of
(
45
)
expect
(
recorded
.
count
).
to
be_within
(
1
).
of
(
38
)
expect
(
recorded
.
cached_count
).
to
eq
(
0
)
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