diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 15:44:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 15:44:42 +0000 |
commit | 4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch) | |
tree | 5423a1c7516cffe36384133ade12572cf709398d /app/models/ci/commit_with_pipeline.rb | |
parent | e570267f2f6b326480d284e0164a6464ba4081bc (diff) | |
download | gitlab-ce-4555e1b21c365ed8303ffb7a3325d773c9b8bf31.tar.gz |
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'app/models/ci/commit_with_pipeline.rb')
-rw-r--r-- | app/models/ci/commit_with_pipeline.rb | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/app/models/ci/commit_with_pipeline.rb b/app/models/ci/commit_with_pipeline.rb index 7f952fb77a0..dde4b534aaa 100644 --- a/app/models/ci/commit_with_pipeline.rb +++ b/app/models/ci/commit_with_pipeline.rb @@ -18,9 +18,25 @@ class Ci::CommitWithPipeline < SimpleDelegator end end + def lazy_latest_pipeline + BatchLoader.for(sha).batch do |shas, loader| + preload_pipelines = project.ci_pipelines.latest_pipeline_per_commit(shas.compact) + + shas.each do |sha| + pipeline = preload_pipelines[sha] + + loader.call(sha, pipeline) + end + end + end + def latest_pipeline(ref = nil) @latest_pipelines.fetch(ref) do |ref| - @latest_pipelines[ref] = latest_pipeline_for_project(ref, project) + @latest_pipelines[ref] = if ref + latest_pipeline_for_project(ref, project) + else + lazy_latest_pipeline&.itself + end end end |