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
1af2274b
Commit
1af2274b
authored
May 25, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Restore lazy loading of pipeline commits in preloader
parent
c0827455
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
6 deletions
+27
-6
lib/gitlab/ci/pipeline/preloader.rb
lib/gitlab/ci/pipeline/preloader.rb
+9
-5
spec/lib/gitlab/ci/pipeline/preloader_spec.rb
spec/lib/gitlab/ci/pipeline/preloader_spec.rb
+18
-1
No files found.
lib/gitlab/ci/pipeline/preloader.rb
View file @
1af2274b
...
@@ -7,9 +7,16 @@ module Gitlab
...
@@ -7,9 +7,16 @@ module Gitlab
# authors.
# authors.
class
Preloader
class
Preloader
def
self
.
preload!
(
pipelines
)
def
self
.
preload!
(
pipelines
)
##
# This preloads all commits at once, because `Ci::Pipeline#commit` is
# using a lazy batch loading, what results in only one batched Gitaly
# call.
#
pipelines
.
each
(
&
:commit
)
pipelines
.
each
do
|
pipeline
|
pipelines
.
each
do
|
pipeline
|
self
.
new
(
pipeline
).
tap
do
|
preloader
|
self
.
new
(
pipeline
).
tap
do
|
preloader
|
preloader
.
preload_commits
preloader
.
preload_commit
_author
s
preloader
.
preload_pipeline_warnings
preloader
.
preload_pipeline_warnings
preloader
.
preload_stages_warnings
preloader
.
preload_stages_warnings
end
end
...
@@ -20,10 +27,7 @@ module Gitlab
...
@@ -20,10 +27,7 @@ module Gitlab
@pipeline
=
pipeline
@pipeline
=
pipeline
end
end
def
preload_commits
def
preload_commit_authors
# This ensures that all the pipeline commits are eager loaded before we
# 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.
@pipeline
.
commit
.
try
(
:lazy_author
)
@pipeline
.
commit
.
try
(
:lazy_author
)
...
...
spec/lib/gitlab/ci/pipeline/preloader_spec.rb
View file @
1af2274b
# frozen_string_literal: true
# frozen_string_literal: true
require
'
fast_
spec_helper'
require
'spec_helper'
describe
Gitlab
::
Ci
::
Pipeline
::
Preloader
do
describe
Gitlab
::
Ci
::
Pipeline
::
Preloader
do
let
(
:stage
)
{
double
(
:stage
)
}
let
(
:stage
)
{
double
(
:stage
)
}
...
@@ -11,6 +11,23 @@ describe Gitlab::Ci::Pipeline::Preloader do
...
@@ -11,6 +11,23 @@ describe Gitlab::Ci::Pipeline::Preloader do
end
end
describe
'.preload!'
do
describe
'.preload!'
do
context
'when preloading multiple commits'
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
it
'preloads all commits once'
do
expect
(
Commit
).
to
receive
(
:decorate
).
once
.
and_call_original
pipelines
=
[
build_pipeline
(
ref:
'HEAD'
),
build_pipeline
(
ref:
'HEAD~1'
)]
described_class
.
preload!
(
pipelines
)
end
def
build_pipeline
(
ref
:)
build_stubbed
(
:ci_pipeline
,
project:
project
,
sha:
project
.
commit
(
ref
).
id
)
end
end
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
)
...
...
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