Skip to content

Resolve "Controller Projects::IssuesController#referenced_merge_requests.json executes more than 100 SQL queries"

What does this MR do?

By commit:

  1. Refactor so that Issue#{referenced,closed_by}_merge_requests are now methods on a service, not the model.
  2. 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.
  3. Fix a N+1 with project routes. This was only likely a problem where MRs in lots of different projects referenced the same issue.
  4. 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.
  5. 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?

Closes #43096 (closed).

Edited by Sean McGivern

Merge request reports