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-22 13:30:45 +0300
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-05-22 13:30:45 +0300
commit6c63f96e0a26fa046fb0cc4664240e37db8b37d8 (patch)
tree60665118a4d454b2d68c4c15a6f76912b3763c4f /app/models/ci/stage.rb
parent9520d2ff278f12cf2e01a755b1ea12213fd22edb (diff)
Preload number of warnings in every stage in a pipeline
This makes it possible to avoid N+1 queries when loading pipelines table.
Diffstat (limited to 'app/models/ci/stage.rb')
-rw-r--r--app/models/ci/stage.rb13
1 files changed, 12 insertions, 1 deletions
diff --git a/app/models/ci/stage.rb b/app/models/ci/stage.rb
index 4fc8a00d9c3..faedb9c29fd 100644
--- a/app/models/ci/stage.rb
+++ b/app/models/ci/stage.rb
@@ -89,7 +89,18 @@ module Ci
end
def has_warnings?
- statuses.latest.failed_but_allowed.any?
+ number_of_warnings.positive?
+ end
+
+ def number_of_warnings
+ BatchLoader.for(id).batch(default_value: 0) do |stage_ids, loader|
+ ::Ci::Build.where(stage_id: stage_ids)
+ .latest
+ .failed_but_allowed
+ .group(:stage_id)
+ .count
+ .each { |id, amount| loader.call(id, amount) }
+ end
end
def detailed_status(current_user)