Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-05-23 11:22:28 +0300
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-05-23 11:22:28 +0300
commitf89f232d19a6c28a3504e964fbfd2b5eb344aa85 (patch)
tree2719792cc1bd3eccf9e16618a2b4046264d7abfa /lib/gitlab/ci/pipeline/preloader.rb
parent0b3cca568ddaa43b4531392a8ccc391b1688bfdc (diff)
Simplify pipelines preloader implementation
Diffstat (limited to 'lib/gitlab/ci/pipeline/preloader.rb')
-rw-r--r--lib/gitlab/ci/pipeline/preloader.rb63
1 files changed, 29 insertions, 34 deletions
diff --git a/lib/gitlab/ci/pipeline/preloader.rb b/lib/gitlab/ci/pipeline/preloader.rb
index 668c1b7189c..6db6554a606 100644
--- a/lib/gitlab/ci/pipeline/preloader.rb
+++ b/lib/gitlab/ci/pipeline/preloader.rb
@@ -6,46 +6,41 @@ module Gitlab
# Class for preloading data associated with pipelines such as commit
# authors.
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
+ def self.preload!(pipelines)
+ pipelines.each do |pipeline|
+ self.new(pipeline).tap do |preloader|
+ preloader.preload_commits
+ preloader.preload_pipeline_warnings
+ preloader.preload_stages_warnings
+ end
end
end
- class Instance
- def initialize(pipeline)
- @pipeline = pipeline
- end
+ def initialize(pipeline)
+ @pipeline = pipeline
+ end
- def preload_commits
- # 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"
- # here since "author" immediately loads the data on the first call.
- tap { @pipeline.commit.try(:lazy_author) }
- end
+ def preload_commits
+ # 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"
+ # here since "author" immediately loads the data on the first call.
+ @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.
- tap { @pipeline.number_of_warnings }
- 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
+ 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.
- tap { @pipeline.stages.each { |stage| stage.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 }
end
end
end