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
ea35fd05
Commit
ea35fd05
authored
May 22, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor pipeline preloader to split reponsibilities better
parent
76a7157c
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
23 deletions
+43
-23
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
+30
-10
spec/controllers/projects/pipelines_controller_spec.rb
spec/controllers/projects/pipelines_controller_spec.rb
+0
-2
spec/lib/gitlab/ci/pipeline/preloader_spec.rb
spec/lib/gitlab/ci/pipeline/preloader_spec.rb
+12
-10
No files found.
app/controllers/projects/pipelines_controller.rb
View file @
ea35fd05
...
...
@@ -24,7 +24,7 @@ class Projects::PipelinesController < Projects::ApplicationController
@finished_count
=
limited_pipelines_count
(
project
,
'finished'
)
@pipelines_count
=
limited_pipelines_count
(
project
)
Gitlab
::
Ci
::
Pipeline
::
Preloader
.
preload
(
@pipelines
)
Gitlab
::
Ci
::
Pipeline
::
Preloader
.
new
(
@pipelines
).
preload!
respond_to
do
|
format
|
format
.
html
...
...
lib/gitlab/ci/pipeline/preloader.rb
View file @
ea35fd05
...
...
@@ -5,26 +5,46 @@ module Gitlab
module
Pipeline
# Class for preloading data associated with pipelines such as commit
# authors.
module
Preloader
def
self
.
preload
(
pipelines
)
class
Preloader
def
initialize
(
pipelines
)
@pipelines
=
pipelines
end
def
preload!
@pipelines
.
each
do
|
pipeline
|
Pipeline
::
Preloader
::
Instance
.
new
(
pipeline
)
.
preload_commits
.
preload_pipeline_warnings
.
preload_stages_warnings
end
end
class
Instance
def
initialize
(
pipeline
)
@pipeline
=
pipeline
end
def
preload_commits
# This ensures that all the pipeline commits are eager loaded before we
# start using them.
pipelines
.
each
(
&
:commit
)
pipelines
.
each
do
|
pipeline
|
# This 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.
pipeline
.
commit
.
try
(
:lazy_author
)
tap
{
@pipeline
.
commit
.
try
(
:lazy_author
)
}
end
def
preload_pipeline_warnings
# This preloads the number of warnings for every pipeline, ensuring
# that Ci::Pipeline#has_warnings? doesn't execute any additional
# queries.
pipeline
.
number_of_warnings
tap
{
@pipeline
.
number_of_warnings
}
end
def
preload_stages_warnings
# This preloads the number of warnings for every stage, ensuring
# that Ci::Stage#has_warnings? doesn't execute any additional
# queries.
pipeline
.
stages
.
each
{
|
stage
|
stage
.
number_of_warnings
}
tap
{
@pipeline
.
stages
.
each
{
|
stage
|
stage
.
number_of_warnings
}
}
end
end
end
...
...
spec/controllers/projects/pipelines_controller_spec.rb
View file @
ea35fd05
...
...
@@ -36,8 +36,6 @@ describe Projects::PipelinesController do
expect
(
json_response
[
'count'
][
'running'
]).
to
eq
'1'
expect
(
json_response
[
'count'
][
'pending'
]).
to
eq
'1'
expect
(
json_response
[
'count'
][
'finished'
]).
to
eq
'2'
puts
queries
.
log
puts
"Queries count:
#{
queries
.
count
}
"
expect
(
queries
.
count
).
to
be
<
32
end
...
...
spec/lib/gitlab/ci/pipeline/preloader_spec.rb
View file @
ea35fd05
# frozen_string_literal: true
require
'spec_helper'
require
'
fast_
spec_helper'
describe
Gitlab
::
Ci
::
Pipeline
::
Preloader
do
describe
'.preload'
do
it
'preloads the author of every pipeline commit'
do
commit
=
double
(
:commit
)
pipeline
=
double
(
:pipeline
,
commit:
commit
)
let
(
:stage
)
{
double
(
:stage
)
}
let
(
:commit
)
{
double
(
:commit
)
}
expect
(
commit
)
.
to
receive
(
:lazy_author
)
let
(
:pipeline
)
do
double
(
:pipeline
,
commit:
commit
,
stages:
[
stage
])
end
expect
(
pipeline
)
.
to
receive
(
:number_of_warnings
)
describe
'#preload!'
do
it
'preloads commit authors and number of warnings'
do
expect
(
commit
).
to
receive
(
:lazy_author
)
expect
(
pipeline
).
to
receive
(
:number_of_warnings
)
expect
(
stage
).
to
receive
(
:number_of_warnings
)
described_class
.
preload
([
pipeline
])
described_class
.
new
([
pipeline
]).
preload!
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