From 0ea3fcec397b69815975647f5e2aa5fe944a8486 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Mon, 20 Jun 2022 11:10:13 +0000 Subject: Add latest changes from gitlab-org/gitlab@15-1-stable-ee --- app/graphql/types/ci/runner_type.rb | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'app/graphql/types/ci/runner_type.rb') diff --git a/app/graphql/types/ci/runner_type.rb b/app/graphql/types/ci/runner_type.rb index 6f957d2511f..949e216a982 100644 --- a/app/graphql/types/ci/runner_type.rb +++ b/app/graphql/types/ci/runner_type.rb @@ -85,6 +85,15 @@ module Types method: :token_expires_at field :version, GraphQL::Types::String, null: true, description: 'Version of the runner.' + field :owner_project, ::Types::ProjectType, null: true, + description: 'Project that owns the runner. For project runners only.', + resolver: ::Resolvers::Ci::RunnerOwnerProjectResolver + + markdown_field :maintenance_note_html, null: true + + def maintenance_note_html_resolver + ::MarkupHelper.markdown(object.maintenance_note, context.to_h.dup) + end def job_count # We limit to 1 above the JOB_COUNT_LIMIT to indicate that more items exist after JOB_COUNT_LIMIT @@ -136,16 +145,22 @@ module Types # rubocop: disable CodeReuse/ActiveRecord def batched_owners(runner_assoc_type, assoc_type, key, column_name) - BatchLoader::GraphQL.for(runner.id).batch(key: key) do |runner_ids, loader, args| - runner_and_owner_ids = runner_assoc_type.where(runner_id: runner_ids).pluck(:runner_id, column_name) - - owner_ids_by_runner_id = runner_and_owner_ids.group_by(&:first).transform_values { |v| v.pluck(1) } - owner_ids = runner_and_owner_ids.pluck(1).uniq - + BatchLoader::GraphQL.for(runner.id).batch(key: key) do |runner_ids, loader| + plucked_runner_and_owner_ids = runner_assoc_type + .select(:runner_id, column_name) + .where(runner_id: runner_ids) + .pluck(:runner_id, column_name) + # In plucked_runner_and_owner_ids, first() represents the runner ID, and second() the owner ID, + # so let's group the owner IDs by runner ID + runner_owner_ids_by_runner_id = plucked_runner_and_owner_ids + .group_by(&:first) + .transform_values { |runner_and_owner_id| runner_and_owner_id.map(&:second) } + + owner_ids = runner_owner_ids_by_runner_id.values.flatten.uniq owners = assoc_type.where(id: owner_ids).index_by(&:id) runner_ids.each do |runner_id| - loader.call(runner_id, owner_ids_by_runner_id[runner_id]&.map { |owner_id| owners[owner_id] } || []) + loader.call(runner_id, runner_owner_ids_by_runner_id[runner_id]&.map { |owner_id| owners[owner_id] } || []) end end end -- cgit v1.2.1