Commit 1532944d authored by Pedro Pombeiro's avatar Pedro Pombeiro Committed by Andreas Brandl

Apply MR review suggestion

parent 332f0c00
...@@ -53,14 +53,16 @@ module Types ...@@ -53,14 +53,16 @@ module Types
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def project_count def project_count
BatchLoader::GraphQL.for(runner).batch(key: :runner_project_count) do |runners, loader, args| BatchLoader::GraphQL.for(runner.id).batch(key: :runner_project_count) do |ids, loader, args|
counts = ::Ci::RunnerProject.select(:runner_id, 'COUNT(*) as count') counts = ::Ci::Runner.project_type
.where(runner_id: runners.map(&:id)) .select(:id, 'COUNT(ci_runner_projects.id) as count')
.group(:runner_id) .left_outer_joins(:runner_projects)
.index_by(&:runner_id) .where(id: ids)
.group(:id)
.index_by(&:id)
runners.each do |runner| ids.each do |id|
loader.call(runner, counts[runner.id]&.count || (runner.project_type? ? 0 : nil)) loader.call(id, counts[id]&.count)
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment