Only load what we need when visiting MR diffs page
The instance variables set in this action are only used by the JSON response. Visiting `merge_requests/:iid/diffs` in a browser always loads the `show` action, so we don't need to find an MR diff, or an environment, in that case.
This commit is contained in:
parent
7a97490526
commit
0344e0838d
2 changed files with 26 additions and 22 deletions
|
@ -97,31 +97,31 @@ class Projects::MergeRequestsController < Projects::ApplicationController
|
|||
def diffs
|
||||
apply_diff_view_cookie!
|
||||
|
||||
@merge_request_diff =
|
||||
if params[:diff_id]
|
||||
@merge_request.merge_request_diffs.viewable.find(params[:diff_id])
|
||||
else
|
||||
@merge_request.merge_request_diff
|
||||
end
|
||||
|
||||
@merge_request_diffs = @merge_request.merge_request_diffs.viewable.select_without_diff
|
||||
@comparable_diffs = @merge_request_diffs.select { |diff| diff.id < @merge_request_diff.id }
|
||||
|
||||
if params[:start_sha].present?
|
||||
@start_sha = params[:start_sha]
|
||||
@start_version = @comparable_diffs.find { |diff| diff.head_commit_sha == @start_sha }
|
||||
|
||||
unless @start_version
|
||||
@start_sha = @merge_request_diff.head_commit_sha
|
||||
@start_version = @merge_request_diff
|
||||
end
|
||||
end
|
||||
|
||||
@environment = @merge_request.environments_for(current_user).last
|
||||
|
||||
respond_to do |format|
|
||||
format.html { define_discussion_vars }
|
||||
format.json do
|
||||
@merge_request_diff =
|
||||
if params[:diff_id]
|
||||
@merge_request.merge_request_diffs.viewable.find(params[:diff_id])
|
||||
else
|
||||
@merge_request.merge_request_diff
|
||||
end
|
||||
|
||||
@merge_request_diffs = @merge_request.merge_request_diffs.viewable.select_without_diff
|
||||
@comparable_diffs = @merge_request_diffs.select { |diff| diff.id < @merge_request_diff.id }
|
||||
|
||||
if params[:start_sha].present?
|
||||
@start_sha = params[:start_sha]
|
||||
@start_version = @comparable_diffs.find { |diff| diff.head_commit_sha == @start_sha }
|
||||
|
||||
unless @start_version
|
||||
@start_sha = @merge_request_diff.head_commit_sha
|
||||
@start_version = @merge_request_diff
|
||||
end
|
||||
end
|
||||
|
||||
@environment = @merge_request.environments_for(current_user).last
|
||||
|
||||
if @start_sha
|
||||
compared_diff_version
|
||||
else
|
||||
|
|
4
changelogs/unreleased/mr-diffs-speed-up.yml
Normal file
4
changelogs/unreleased/mr-diffs-speed-up.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
title: Speed up initial rendering of MR diffs page
|
||||
merge_request:
|
||||
author:
|
Loading…
Reference in a new issue