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
Jérome Perrin
gitlab-ce
Commits
c698f109
Commit
c698f109
authored
Jun 02, 2017
by
Felipe Artur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid repeated queries for pipeline builds on merge requests
parent
de3e1bb4
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
6 deletions
+37
-6
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+2
-2
app/serializers/pipeline_serializer.rb
app/serializers/pipeline_serializer.rb
+4
-3
changelogs/unreleased/issue_27166_2.yml
changelogs/unreleased/issue_27166_2.yml
+4
-0
spec/features/merge_requests/mini_pipeline_graph_spec.rb
spec/features/merge_requests/mini_pipeline_graph_spec.rb
+27
-1
No files found.
app/models/ci/pipeline.rb
View file @
c698f109
...
@@ -25,8 +25,8 @@ module Ci
...
@@ -25,8 +25,8 @@ module Ci
has_many
:pending_builds
,
->
{
pending
},
foreign_key: :commit_id
,
class_name:
'Ci::Build'
has_many
:pending_builds
,
->
{
pending
},
foreign_key: :commit_id
,
class_name:
'Ci::Build'
has_many
:retryable_builds
,
->
{
latest
.
failed_or_canceled
},
foreign_key: :commit_id
,
class_name:
'Ci::Build'
has_many
:retryable_builds
,
->
{
latest
.
failed_or_canceled
},
foreign_key: :commit_id
,
class_name:
'Ci::Build'
has_many
:cancelable_statuses
,
->
{
cancelable
},
foreign_key: :commit_id
,
class_name:
'CommitStatus'
has_many
:cancelable_statuses
,
->
{
cancelable
},
foreign_key: :commit_id
,
class_name:
'CommitStatus'
has_many
:manual_actions
,
->
{
latest
.
manual_actions
},
foreign_key: :commit_id
,
class_name:
'Ci::Build'
has_many
:manual_actions
,
->
{
latest
.
manual_actions
.
includes
(
:project
)
},
foreign_key: :commit_id
,
class_name:
'Ci::Build'
has_many
:artifacts
,
->
{
latest
.
with_artifacts_not_expired
},
foreign_key: :commit_id
,
class_name:
'Ci::Build'
has_many
:artifacts
,
->
{
latest
.
with_artifacts_not_expired
.
includes
(
:project
)
},
foreign_key: :commit_id
,
class_name:
'Ci::Build'
delegate
:id
,
to: :project
,
prefix:
true
delegate
:id
,
to: :project
,
prefix:
true
...
...
app/serializers/pipeline_serializer.rb
View file @
c698f109
...
@@ -13,14 +13,15 @@ class PipelineSerializer < BaseSerializer
...
@@ -13,14 +13,15 @@ class PipelineSerializer < BaseSerializer
def
represent
(
resource
,
opts
=
{})
def
represent
(
resource
,
opts
=
{})
if
resource
.
is_a?
(
ActiveRecord
::
Relation
)
if
resource
.
is_a?
(
ActiveRecord
::
Relation
)
resource
=
resource
.
preload
([
resource
=
resource
.
preload
([
:retryable_builds
,
:retryable_builds
,
:cancelable_statuses
,
:cancelable_statuses
,
:trigger_requests
,
:trigger_requests
,
:project
,
:project
,
{
pending_builds: :project
}
,
:manual_actions
,
{
manual_actions: :project
}
,
:artifacts
,
{
artifact
s: :project
}
{
pending_build
s: :project
}
])
])
end
end
...
...
changelogs/unreleased/issue_27166_2.yml
0 → 100644
View file @
c698f109
---
title
:
Avoid repeated queries for pipeline builds on merge requests
merge_request
:
author
:
spec/features/merge_requests/mini_pipeline_graph_spec.rb
View file @
c698f109
...
@@ -12,13 +12,39 @@ feature 'Mini Pipeline Graph', :js, :feature do
...
@@ -12,13 +12,39 @@ feature 'Mini Pipeline Graph', :js, :feature do
build
.
run
build
.
run
login_as
(
user
)
login_as
(
user
)
visit
namespace_project_merge_request_path
(
project
.
namespace
,
project
,
merge_request
)
visit_merge_request
end
def
visit_merge_request
(
format
=
:html
)
visit
namespace_project_merge_request_path
(
project
.
namespace
,
project
,
merge_request
,
format:
format
)
end
end
it
'should display a mini pipeline graph'
do
it
'should display a mini pipeline graph'
do
expect
(
page
).
to
have_selector
(
'.mr-widget-pipeline-graph'
)
expect
(
page
).
to
have_selector
(
'.mr-widget-pipeline-graph'
)
end
end
context
'as json'
do
let
(
:artifacts_file1
)
{
fixture_file_upload
(
Rails
.
root
+
'spec/fixtures/banana_sample.gif'
,
'image/gif'
)
}
let
(
:artifacts_file2
)
{
fixture_file_upload
(
Rails
.
root
+
'spec/fixtures/dk.png'
,
'image/png'
)
}
before
do
create
(
:ci_build
,
pipeline:
pipeline
,
artifacts_file:
artifacts_file1
)
create
(
:ci_build
,
pipeline:
pipeline
,
when:
'manual'
)
end
it
'avoids repeated database queries'
do
before
=
ActiveRecord
::
QueryRecorder
.
new
{
visit_merge_request
(
:json
)
}
create
(
:ci_build
,
pipeline:
pipeline
,
artifacts_file:
artifacts_file2
)
create
(
:ci_build
,
pipeline:
pipeline
,
when:
'manual'
)
after
=
ActiveRecord
::
QueryRecorder
.
new
{
visit_merge_request
(
:json
)
}
expect
(
before
.
count
).
to
eq
(
after
.
count
)
expect
(
before
.
cached_count
).
to
eq
(
after
.
cached_count
)
end
end
describe
'build list toggle'
do
describe
'build list toggle'
do
let
(
:toggle
)
do
let
(
:toggle
)
do
find
(
'.mini-pipeline-graph-dropdown-toggle'
)
find
(
'.mini-pipeline-graph-dropdown-toggle'
)
...
...
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