Resolve "Controller Projects::IssuesController#referenced_merge_requests.json executes more than 100 SQL queries"
requested to merge 43096-controller-projects-issuescontroller-referenced_merge_requests-json-executes-more-than-100-sql-queries into master
What does this MR do?
By commit:
- Refactor so that
Issue#{referenced,closed_by}_merge_requests
are now methods on a service, not the model. - Fix a small N+1: we'd load each note's author individually. It also fixes a small issue where we'd load, for instance, award emoji unnecessarily.
- Fix a N+1 with project routes. This was only likely a problem where MRs in lots of different projects referenced the same issue.
- Fix a N+1 with CI pipelines for MRs. This is quite dramatic on https://gitlab.com/gitlab-org/gitlab-ce/issues/47424, for instance.
- Only load the issue notes once - as we always call both methods in this controller, and one uses all notes and the other uses system notes, then we should just load the notes and their authors once, and filter on the Ruby side.
Does this MR meet the acceptance criteria?
-
Changelog entry added, if necessary -
Tests added for this feature/bug -
Conforms to the code review guidelines -
Conforms to the merge request performance guidelines -
Conforms to the style guides -
Conforms to the database guides
Closes #43096 (closed).
Edited by Sean McGivern