BigW Consortium Gitlab

Commit 8e388fca by Rémy Coutable

Get rid of a first N+1 query problem

Use the same approach in Banzai::Filter::MergeRequestReferenceFilter as we do with issues. Signed-off-by: 's avatarRémy Coutable <remy@rymai.me>
parent 20bada33
......@@ -11,8 +11,8 @@ module Banzai
MergeRequest
end
def find_object(project, id)
project.merge_requests.find_by(iid: id)
def find_object(project, iid)
merge_requests_per_project[project][iid]
end
def url_for_object(mr, project)
......@@ -21,6 +21,25 @@ module Banzai
only_path: context[:only_path])
end
# Returns a Hash containing the merge_requests per Project instance.
def merge_requests_per_project
@merge_requests_per_project ||= begin
hash = Hash.new { |h, k| h[k] = {} }
projects_per_reference.each do |path, project|
merge_request_ids = references_per_project[path]
merge_requests = project.merge_requests.where(iid: merge_request_ids.to_a)
merge_requests.each do |merge_request|
hash[project][merge_request.iid.to_i] = merge_request
end
end
hash
end
end
def object_link_text_extras(object, matches)
extras = super
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment