From b870ae1f59ab0b3f4a10f9dbb2d64324b90ba38b Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Mon, 28 Aug 2017 17:35:10 +0200 Subject: [PATCH] Eager load head pipeline projects for MRs index This ensures the project of an MR's head pipeline is eager loaded, preventing an N+1 query problem from occurring when viewing the list of MRs of a project. --- app/controllers/concerns/issuable_collections.rb | 12 +++++++++++- changelogs/unreleased/mr-index-eager-load.yml | 5 +++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/mr-index-eager-load.yml diff --git a/app/controllers/concerns/issuable_collections.rb b/app/controllers/concerns/issuable_collections.rb index b43b2c5621f..a34a82b7ba6 100644 --- a/app/controllers/concerns/issuable_collections.rb +++ b/app/controllers/concerns/issuable_collections.rb @@ -15,7 +15,17 @@ module IssuableCollections end def merge_requests_collection - merge_requests_finder.execute.preload(:source_project, :target_project, :author, :assignee, :labels, :milestone, :head_pipeline, target_project: :namespace, merge_request_diff: :merge_request_diff_commits) + merge_requests_finder.execute.preload( + :source_project, + :target_project, + :author, + :assignee, + :labels, + :milestone, + head_pipeline: :project, + target_project: :namespace, + merge_request_diff: :merge_request_diff_commits + ) end def issues_finder diff --git a/changelogs/unreleased/mr-index-eager-load.yml b/changelogs/unreleased/mr-index-eager-load.yml new file mode 100644 index 00000000000..11c33055b17 --- /dev/null +++ b/changelogs/unreleased/mr-index-eager-load.yml @@ -0,0 +1,5 @@ +--- +title: Eager load head pipeline projects for MRs index +merge_request: +author: +type: other