diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-24 03:10:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-24 03:10:25 +0300 |
commit | b2e2c43b3c5aebf47d7f6114b172551e4fa97e58 (patch) | |
tree | 5358eb8e4b7fa85f87f13524ab520b460a62ce24 /app/graphql | |
parent | 5838993b5f3e2d861d9dd7c82dfeea71506b9fc2 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/graphql')
-rw-r--r-- | app/graphql/types/ci/stage_type.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/app/graphql/types/ci/stage_type.rb b/app/graphql/types/ci/stage_type.rb index fd0bde90836..da3227111cd 100644 --- a/app/graphql/types/ci/stage_type.rb +++ b/app/graphql/types/ci/stage_type.rb @@ -16,6 +16,26 @@ module Types def detailed_status object.detailed_status(context[:current_user]) end + + # Issues one query per pipeline + def groups + BatchLoader::GraphQL.for([object.pipeline, object]).batch(default_value: []) do |keys, loader| + by_pipeline = keys.group_by(&:first) + + by_pipeline.each do |pl, key_group| + project = pl.project + stages = key_group.map(&:second).uniq + indexed = stages.index_by(&:id) + results = pl.latest_statuses.where(stage_id: stages.map(&:id)) # rubocop: disable CodeReuse/ActiveRecord + + results.group_by(&:stage_id).each do |stage_id, statuses| + stage = indexed[stage_id] + groups = ::Ci::Group.fabricate(project, stage, statuses) + loader.call([pl, stage], groups) + end + end + end + end end end end |