Skip to content

Add issue health status sorting to GraphQL

Nicolas Dular requested to merge nd/add-health-status-filtering into master

What does this MR do and why?

Issue: #371279 (closed)

This adds the ability to sort issues in GraphQl queries based on their health status via the HEALTH_STATUS_ASC and HEALTH_STATUS_DESC enums.

  • When ascending, healthy issues will be shown first (on track, needs attention, at risk).
  • When descending, unhealthy issues will be shown first (at risk, needs attention, on track).
  • Issues without a health status will always be shown last.

Screenshots or screen recordings

Screenshot_2022-10-19_at_16.56.16

Screenshot_2022-10-19_at_16.56.24

How to set up and validate locally

  1. Create issues with different health status
  2. Query the issues in graphql explorer http://gdk.test:3000/-/graphql-explorer
query Issues {
  group(fullPath: "gitlab-org") {
    issues(sort: HEALTH_STATUS_DESC){ # OR HEALTH_STATUS_ASC
      edges{
        node{
          id
          healthStatus
        }
      }
    }
  }
}

Database Query

SELECT
  "issues".*
FROM
  "issues"
WHERE
  "issues"."project_id" = 278964
  AND ("issues"."state_id" IN (1))
  AND "issues"."issue_type" IN (0, 1, 2, 4)
ORDER BY
  "issues"."health_status" ASC NULLS LAST,
  "issues"."id" DESC
LIMIT 21;

https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/12710/commands/44771 (internal only)

Database Migration

Migrate
r db:migrate
main: == 20221110150140 AddIndexForIssuesHealthStatusOrder: migrating ===============
main: -- index_exists?(:issues, [:project_id, :health_status, :id], {:order=>{:id=>:desc}, :where=>"state_id = 1 AND issue_type = ANY(ARRAY[1, 2, 3, 4])", :name=>"index_on_open_issues_health_status_desc_order", :algorithm=>:concurrently})
main:    -> 0.0093s
main: -- add_index_options(:issues, [:project_id, :health_status, :id], {:order=>{:id=>:desc}, :where=>"state_id = 1 AND issue_type = ANY(ARRAY[1, 2, 3, 4])", :name=>"index_on_open_issues_health_status_desc_order", :algorithm=>:concurrently})
main:    -> 0.0001s
main: == 20221110150140 AddIndexForIssuesHealthStatusOrder: migrated (0.0235s) ======

ci: == 20221110150140 AddIndexForIssuesHealthStatusOrder: migrating ===============
ci: -- index_exists?(:issues, [:project_id, :health_status, :id], {:order=>{:id=>:desc}, :where=>"state_id = 1 AND issue_type = ANY(ARRAY[1, 2, 3, 4])", :name=>"index_on_open_issues_health_status_desc_order", :algorithm=>:concurrently})
ci:    -> 0.0092s
ci: == 20221110150140 AddIndexForIssuesHealthStatusOrder: migrated (0.0101s) ======
Rollback
r db:rollback:main db:rollback:ci
main: == 20221110150140 AddIndexForIssuesHealthStatusOrder: reverting ===============
main: -- index_name(:issues, "index_on_open_issues_health_status_desc_order")
main:    -> 0.0000s
main: == 20221110150140 AddIndexForIssuesHealthStatusOrder: reverted (0.0068s) ======

ci: == 20221110150140 AddIndexForIssuesHealthStatusOrder: reverting ===============
ci: -- index_name(:issues, "index_on_open_issues_health_status_desc_order")
ci:    -> 0.0000s
ci: == 20221110150140 AddIndexForIssuesHealthStatusOrder: reverted (0.0025s) ======

Resulting Index:

exec CREATE INDEX index_on_open_issues_health_status_desc_order ON issues USING btree (project_id, health_status, id DESC) WHERE ((state_id = 1) AND (issue_type = ANY (ARRAY[1, 2, 3, 4])));

MR acceptance checklist

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

Edited by Nicolas Dular

Merge request reports