Commit b963d45c authored by Stan Hu's avatar Stan Hu

Remove many N+1 queries with merge requests API

Identified via `ENABLE_BULLET=1 bundle exec rspec spec/requests/api/merge_requests_spec.rb:34`

Improves speed of #34159
parent 426271da
......@@ -14,7 +14,7 @@ class MergeRequest < ActiveRecord::Base
has_many :merge_request_diffs
has_one :merge_request_diff,
-> { order('merge_request_diffs.id DESC') }
-> { order('merge_request_diffs.id DESC') }, inverse_of: :merge_request
belongs_to :head_pipeline, foreign_key: "head_pipeline_id", class_name: "Ci::Pipeline"
......
......@@ -41,7 +41,9 @@ module API
args[:milestone_title] = args.delete(:milestone)
args[:label_name] = args.delete(:labels)
merge_requests = MergeRequestsFinder.new(current_user, args).execute.inc_notes_with_associations
merge_requests = MergeRequestsFinder.new(current_user, args).execute
.inc_notes_with_associations
.preload(:target_project, :author, :assignee, :milestone, :merge_request_diff)
merge_requests.reorder(args[:order_by] => args[:sort])
end
......
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