Fix N+1 queries with autocomplete recent items
What does this MR do and why?
Related to #444491 (closed)
Added specs to check for N+1 in autocomplete for recently viewed issues
, merge requests
, and epics
Added preloading to make the specs pass
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots or screen recordings
N/A - backend changes
How to set up and validate locally
- create 3 issues with the same title in 3 different projects. I used FactoryBot in rails console but you can use the UI too. The line below will also create 3 new projects
FactoryBot.create_list(:issue, 3, title: 'same title')
- Open each issue in the UI to load it into cache as a recent issue
- Open the command palette and search for the title, all 3 issues should come back as recent issue
- use the performance bar to look at the
autocomplete?term=XXXXX&source=generic
request. - see that N+1 queries are not generated for the project, namespace or routes
Do the same thing for merge requests and epics. Create commands are below
FactoryBot.create_list(:merge_request, 3, :unique_branches, title: 'same title')
FactoryBot.create_list(:epic, 3, title: 'same title')
Edited by Terri Chu