Skip to content

Add support for querying work items counts by state

What does this MR do and why?

Related to #390865 (closed)

Add support for querying work item counts by state at group and project level. These fields support work item filters so they can be used on the listing page tabs to display the counts for the list. For example:

Screenshot 2023-12-05 at 14.51.38.png

To improve performance these counts are cached (expiring every 1 hour) when meeting the following conditions:

  • The work item counts are queried at the group level
  • All state counts are higher than 1000
  • The results are not filtered

We might expand the caching to the project level in future iterations but for now, it just matches the options we have for issues.

Example queries:

query groupWorkItemsCounts {
  workspace: group(fullPath: "group-a") {
    workItemStateCounts {
      opened
      closed
      all
    }
  }
}

query projectWorkItemsCounts {
  workspace: project(fullPath: "group-a/project-a") {
    workItemStateCounts {
      opened
      closed
      all
    }
  }
}

Screenshots or screen recordings

Group query Project query
Screenshot_2023-12-05_at_14.41.02 Screenshot_2023-12-05_at_14.40.17

How to set up and validate locally

  1. Using the rails console enable the FF for work items at the group level Feature.enable(:namespace_level_work_items)

  2. Visit http://127.0.0.1:3000/-/graphql-explorer and create work items at the group and project level

    example mutations
    workItemGroupCreate(input: { namespacePath: "group-a", title: "Test Epic", workItemTypeId: "gid://gitlab/WorkItems::Type/8" }) {
        errors
        workItem {
          id
          webUrl
          workItemType {
            name
          }
        }
      }
    
      workItemProjectCreate(input: { namespacePath: "group-a/project-a", title: "Test Task", workItemTypeId: "gid://gitlab/WorkItems::Type/5" }) {
        errors
        workItem {
          id
          webUrl
          workItemType {
            name
          }
        }
      }
  3. Test the example queries and verify that the counts change when updating the work items' state. Adding filters to the workItem field should also modify the counts.

  4. To verify the caching modify Gitlab::IssuablesCountForState::THRESHOLD to be lower than all counts in your example and use gdk tail rails-web to make sure that the group query only performs one SELECT COUNT(*) DB query.

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 Eugenia Grieff

Merge request reports