Skip to content

Draft: Extend Ci::RunnersFinder to allow grouping of results

What does this MR do and why?

Describe in detail what your merge request does and why.

NOTE: The commits in this MR are individually reviewable

This MR does some changes in order to be able to replace the 4 sequential SQL queries in Ci::RunnersHelper#admin_runners_data_attributes with a single SQL query performed by Ci::RunnersFinder#execute:

  • 1st commit: Allow grouping results from RunnersFinder
  • 2nd commit: Allow NumbersHelper to receive count directly
  • 3rd commit: Replace 4 runner count queries with a single one

For context, these queries will soon be running more often: currently they run once per page load, but the intent is to make the sounds reflect any filtering, so we'll be refreshing them whenever the filter changes.

Screenshots or screen recordings

These are strongly recommended to assist reviewers and reduce the time to merge your change.

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

By navigating to http://gdk.test:3000/admin/runners, there should be a single SQL query fetching counts:

  Rendering admin/runners/index.html.haml within layouts/admin
   (2.3ms)  SELECT COUNT(*) AS count_all, "ci_runners"."runner_type" AS ci_runners_runner_type FROM "ci_runners" GROUP BY "ci_runners"."runner_type" /*application:web,correlation_id:01FPFGD2BSR9T7051XKT880YCW,endpoint_id:Admin::RunnersController#index,db_config_name:main,line:/app/models/ci/runner.rb:140:in `block in <class:Runner>'*/

The version in master performs 4 queries as can be seen from the logs:

   (0.5ms)  SELECT COUNT(*) FROM (SELECT 1 AS one FROM "ci_runners" LIMIT 1001) subquery_for_count /*application:web,correlation_id:01FPFH11Y2W25R7B3J60CDRYQ3,endpoint_id:Admin::RunnersController#index,db_config_name:main,line:/app/helpers/numbers_helper.rb:6:in `limited_counter_with_delimiter'*/
  ↳ config/initializers/kaminari_active_record_relation_methods_with_limit.rb:31:in `total_count_with_limit'
   (0.6ms)  SELECT COUNT(*) FROM (SELECT 1 AS one FROM "ci_runners" WHERE "ci_runners"."runner_type" = 1 LIMIT 1001) subquery_for_count /*application:web,correlation_id:01FPFH11Y2W25R7B3J60CDRYQ3,endpoint_id:Admin::RunnersController#index,db_config_name:main,line:/app/helpers/numbers_helper.rb:6:in `limited_counter_with_delimiter'*/
  ↳ config/initializers/kaminari_active_record_relation_methods_with_limit.rb:31:in `total_count_with_limit'
   (0.5ms)  SELECT COUNT(*) FROM (SELECT 1 AS one FROM "ci_runners" WHERE "ci_runners"."runner_type" = 2 LIMIT 1001) subquery_for_count /*application:web,correlation_id:01FPFH11Y2W25R7B3J60CDRYQ3,endpoint_id:Admin::RunnersController#index,db_config_name:main,line:/app/helpers/numbers_helper.rb:6:in `limited_counter_with_delimiter'*/
  ↳ config/initializers/kaminari_active_record_relation_methods_with_limit.rb:31:in `total_count_with_limit'
   (0.4ms)  SELECT COUNT(*) FROM (SELECT 1 AS one FROM "ci_runners" WHERE "ci_runners"."runner_type" = 3 LIMIT 1001) subquery_for_count /*application:web,correlation_id:01FPFH11Y2W25R7B3J60CDRYQ3,endpoint_id:Admin::RunnersController#index,db_config_name:main,line:/app/helpers/numbers_helper.rb:6:in `limited_counter_with_delimiter'*/
  ↳ config/initializers/kaminari_active_record_relation_methods_with_limit.rb:31:in `total_count_with_limit'

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Closes #345728 (closed)

Merge request reports