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
f89f232d
Commit
f89f232d
authored
May 23, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify pipelines preloader implementation
parent
0b3cca56
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
37 deletions
+32
-37
app/controllers/projects/pipelines_controller.rb
app/controllers/projects/pipelines_controller.rb
+1
-1
lib/gitlab/ci/pipeline/preloader.rb
lib/gitlab/ci/pipeline/preloader.rb
+29
-34
spec/lib/gitlab/ci/pipeline/preloader_spec.rb
spec/lib/gitlab/ci/pipeline/preloader_spec.rb
+2
-2
No files found.
app/controllers/projects/pipelines_controller.rb
View file @
f89f232d
...
@@ -24,7 +24,7 @@ class Projects::PipelinesController < Projects::ApplicationController
...
@@ -24,7 +24,7 @@ class Projects::PipelinesController < Projects::ApplicationController
@finished_count
=
limited_pipelines_count
(
project
,
'finished'
)
@finished_count
=
limited_pipelines_count
(
project
,
'finished'
)
@pipelines_count
=
limited_pipelines_count
(
project
)
@pipelines_count
=
limited_pipelines_count
(
project
)
Gitlab
::
Ci
::
Pipeline
::
Preloader
.
new
(
@pipelines
).
preload!
Gitlab
::
Ci
::
Pipeline
::
Preloader
.
preload!
(
@pipelines
)
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
html
format
.
html
...
...
lib/gitlab/ci/pipeline/preloader.rb
View file @
f89f232d
...
@@ -6,46 +6,41 @@ module Gitlab
...
@@ -6,46 +6,41 @@ module Gitlab
# Class for preloading data associated with pipelines such as commit
# Class for preloading data associated with pipelines such as commit
# authors.
# authors.
class
Preloader
class
Preloader
def
initialize
(
pipelines
)
def
self
.
preload!
(
pipelines
)
@pipelines
=
pipelines
pipelines
.
each
do
|
pipeline
|
end
self
.
new
(
pipeline
).
tap
do
|
preloader
|
preloader
.
preload_commits
def
preload!
preloader
.
preload_pipeline_warnings
@pipelines
.
each
do
|
pipeline
|
preloader
.
preload_stages_warnings
Pipeline
::
Preloader
::
Instance
.
new
(
pipeline
)
end
.
preload_commits
.
preload_pipeline_warnings
.
preload_stages_warnings
end
end
end
end
class
Instance
def
initialize
(
pipeline
)
def
initialize
(
pipeline
)
@pipeline
=
pipeline
@pipeline
=
pipeline
end
end
def
preload_commits
def
preload_commits
# This ensures that all the pipeline commits are eager loaded before we
# This ensures that all the pipeline commits are eager loaded before we
# start using them.
# start using them.
#
#
# This also preloads the author of every commit. We're using "lazy_author"
# This also preloads the author of every commit. We're using "lazy_author"
# here since "author" immediately loads the data on the first call.
# here since "author" immediately loads the data on the first call.
tap
{
@pipeline
.
commit
.
try
(
:lazy_author
)
}
@pipeline
.
commit
.
try
(
:lazy_author
)
end
end
def
preload_pipeline_warnings
def
preload_pipeline_warnings
# This preloads the number of warnings for every pipeline, ensuring
# This preloads the number of warnings for every pipeline, ensuring
# that Ci::Pipeline#has_warnings? doesn't execute any additional
# that Ci::Pipeline#has_warnings? doesn't execute any additional
# queries.
# queries.
tap
{
@pipeline
.
number_of_warnings
}
@pipeline
.
number_of_warnings
end
end
def
preload_stages_warnings
def
preload_stages_warnings
# This preloads the number of warnings for every stage, ensuring
# This preloads the number of warnings for every stage, ensuring
# that Ci::Stage#has_warnings? doesn't execute any additional
# that Ci::Stage#has_warnings? doesn't execute any additional
# queries.
# queries.
tap
{
@pipeline
.
stages
.
each
{
|
stage
|
stage
.
number_of_warnings
}
}
@pipeline
.
stages
.
each
{
|
stage
|
stage
.
number_of_warnings
}
end
end
end
end
end
end
end
...
...
spec/lib/gitlab/ci/pipeline/preloader_spec.rb
View file @
f89f232d
...
@@ -10,13 +10,13 @@ describe Gitlab::Ci::Pipeline::Preloader do
...
@@ -10,13 +10,13 @@ describe Gitlab::Ci::Pipeline::Preloader do
double
(
:pipeline
,
commit:
commit
,
stages:
[
stage
])
double
(
:pipeline
,
commit:
commit
,
stages:
[
stage
])
end
end
describe
'
#
preload!'
do
describe
'
.
preload!'
do
it
'preloads commit authors and number of warnings'
do
it
'preloads commit authors and number of warnings'
do
expect
(
commit
).
to
receive
(
:lazy_author
)
expect
(
commit
).
to
receive
(
:lazy_author
)
expect
(
pipeline
).
to
receive
(
:number_of_warnings
)
expect
(
pipeline
).
to
receive
(
:number_of_warnings
)
expect
(
stage
).
to
receive
(
:number_of_warnings
)
expect
(
stage
).
to
receive
(
:number_of_warnings
)
described_class
.
new
([
pipeline
]).
preload!
described_class
.
preload!
([
pipeline
])
end
end
end
end
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