Fix N+1 queries in work items REST API
What does this MR do and why?
Fix N+1 queries in work items REST API
- Pass resource_parent option to labels entity to check scoped_labels license once per request instead of per work item
- Add context-aware preloads for project vs group work items
- Preload namespace.route for URL/reference generation
- Preload milestone.project/group for milestone web_url
- Add shared N+1 query prevention test
References
Screenshots or screen recordings
| Before | After |
|---|---|
![]() |
![]() |
How to set up and validate locally
- Enable
work_item_rest_apifeature flag - Compare the amount of queries for the request between
masterand this branch: http://gdk.test:3000/api/v4/namespaces/gitlab/-/work_items?features=milestone,labels&fields=promoted_to_epic_url,web_url,web_path,reference,create_note_email,work_item_type&per_page=100 - You can compare it by copying the
correlation-idfrom the request header, and add it to the performance bar
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Edited by Nicolas Dular




