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:
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 |
---|---|
How to set up and validate locally
-
Using the rails console enable the FF for work items at the group level
Feature.enable(:namespace_level_work_items
) -
Visit
http://127.0.0.1:3000/-/graphql-explorer
and create work items at the group and project levelexample 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 } } }
-
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. -
To verify the caching modify
Gitlab::IssuablesCountForState::THRESHOLD
to be lower than all counts in your example and usegdk tail rails-web
to make sure that the group query only performs oneSELECT 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.
-
I have evaluated the MR acceptance checklist for this MR.