Skip to content

Fix N+1 queries with autocomplete recent items

Terri Chu requested to merge 444491-query-performance-improvements into master

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

  1. 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')
  2. Open each issue in the UI to load it into cache as a recent issue
  3. Open the command palette and search for the title, all 3 issues should come back as recent issue image
  4. use the performance bar to look at the autocomplete?term=XXXXX&source=generic request.
  5. 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')

image

Edited by Terri Chu

Merge request reports