Commit 6a355d45 authored by Douwe Maan's avatar Douwe Maan
Browse files

Improve performance of MR show page

parent ac89bb0f
...@@ -471,7 +471,7 @@ def define_diff_comment_vars ...@@ -471,7 +471,7 @@ def define_diff_comment_vars
} }
@use_legacy_diff_notes = !@merge_request.has_complete_diff_refs? @use_legacy_diff_notes = !@merge_request.has_complete_diff_refs?
@grouped_diff_discussions = @merge_request.notes.inc_author_project_award_emoji.grouped_diff_discussions @grouped_diff_discussions = @merge_request.notes.inc_relations_for_view.grouped_diff_discussions
Banzai::NoteRenderer.render( Banzai::NoteRenderer.render(
@grouped_diff_discussions.values.flat_map(&:notes), @grouped_diff_discussions.values.flat_map(&:notes),
......
...@@ -32,6 +32,8 @@ def brand_header_logo ...@@ -32,6 +32,8 @@ def brand_header_logo
end end
def custom_icon(icon_name, size: 16) def custom_icon(icon_name, size: 16)
# We can't simply do the below, because there are some .erb SVGs.
# File.read(Rails.root.join("app/views/shared/icons/_#{icon_name}.svg")).html_safe
render "shared/icons/#{icon_name}.svg", size: size render "shared/icons/#{icon_name}.svg", size: size
end end
end end
...@@ -4,8 +4,6 @@ class DiffNote < Note ...@@ -4,8 +4,6 @@ class DiffNote < Note
serialize :original_position, Gitlab::Diff::Position serialize :original_position, Gitlab::Diff::Position
serialize :position, Gitlab::Diff::Position serialize :position, Gitlab::Diff::Position
belongs_to :resolved_by, class_name: "User"
validates :original_position, presence: true validates :original_position, presence: true
validates :position, presence: true validates :position, presence: true
validates :diff_line, presence: true validates :diff_line, presence: true
......
...@@ -420,7 +420,7 @@ def mr_and_commit_notes ...@@ -420,7 +420,7 @@ def mr_and_commit_notes
def discussions def discussions
@discussions ||= self.mr_and_commit_notes. @discussions ||= self.mr_and_commit_notes.
inc_author_project_award_emoji. inc_relations_for_view.
fresh. fresh.
discussions discussions
end end
......
...@@ -25,6 +25,9 @@ class Note < ActiveRecord::Base ...@@ -25,6 +25,9 @@ class Note < ActiveRecord::Base
belongs_to :author, class_name: "User" belongs_to :author, class_name: "User"
belongs_to :updated_by, class_name: "User" belongs_to :updated_by, class_name: "User"
# Only used by DiffNote, but defined here so that it can be used in `Note.includes`
belongs_to :resolved_by, class_name: "User"
has_many :todos, dependent: :destroy has_many :todos, dependent: :destroy
has_many :events, as: :target, dependent: :destroy has_many :events, as: :target, dependent: :destroy
...@@ -59,7 +62,7 @@ class Note < ActiveRecord::Base ...@@ -59,7 +62,7 @@ class Note < ActiveRecord::Base
scope :fresh, ->{ order(created_at: :asc, id: :asc) } scope :fresh, ->{ order(created_at: :asc, id: :asc) }
scope :inc_author_project, ->{ includes(:project, :author) } scope :inc_author_project, ->{ includes(:project, :author) }
scope :inc_author, ->{ includes(:author) } scope :inc_author, ->{ includes(:author) }
scope :inc_author_project_award_emoji, ->{ includes(:project, :author, :award_emoji) } scope :inc_relations_for_view, ->{ includes(:project, :author, :updated_by, :resolved_by, :award_emoji) }
scope :diff_notes, ->{ where(type: ['LegacyDiffNote', 'DiffNote']) } scope :diff_notes, ->{ where(type: ['LegacyDiffNote', 'DiffNote']) }
scope :non_diff_notes, ->{ where(type: ['Note', nil]) } scope :non_diff_notes, ->{ where(type: ['Note', nil]) }
......
...@@ -7,8 +7,11 @@ ...@@ -7,8 +7,11 @@
.diff-content.code.js-syntax-highlight .diff-content.code.js-syntax-highlight
%table %table
- discussion.truncated_diff_lines.each do |line| - discussions = { discussion.line_code => discussion }
= render "projects/diffs/line", line: line, diff_file: diff_file, plain: true = render partial: "projects/diffs/line",
collection: discussion.truncated_diff_lines,
- if discussion.for_line?(line) as: :line,
= render "discussions/diff_discussion", discussion: discussion, expanded: true locals: { diff_file: diff_file,
discussions: discussions,
discussion_expanded: true,
plain: true }
...@@ -75,8 +75,7 @@ ...@@ -75,8 +75,7 @@
- blob = diff_file.blob - blob = diff_file.blob
- if blob && blob.respond_to?(:text?) && blob_text_viewable?(blob) - if blob && blob.respond_to?(:text?) && blob_text_viewable?(blob)
%table.code.white %table.code.white
- diff_file.highlighted_diff_lines.each do |line| = render partial: "projects/diffs/line", collection: diff_file.highlighted_diff_lines, as: :line, locals: { diff_file: diff_file, plain: true, email: true }
= render "projects/diffs/line", line: line, diff_file: diff_file, plain: true, email: true
- else - else
No preview for this file type No preview for this file type
%br %br
- email = local_assigns.fetch(:email, false) - email = local_assigns.fetch(:email, false)
- plain = local_assigns.fetch(:plain, false) - plain = local_assigns.fetch(:plain, false)
- type = line.type - type = line.type
- line_code = diff_file.line_code(line) unless plain - line_code = diff_file.line_code(line)
%tr.line_holder{ plain ? { class: type} : { class: type, id: line_code } } %tr.line_holder{ plain ? { class: type} : { class: type, id: line_code } }
- case type - case type
- when 'match' - when 'match'
...@@ -28,3 +28,10 @@ ...@@ -28,3 +28,10 @@
%pre= diff_line_content(line.text, type) %pre= diff_line_content(line.text, type)
- else - else
= diff_line_content(line.text, type) = diff_line_content(line.text, type)
- discussions = local_assigns.fetch(:discussions, nil)
- discussion_expanded = local_assigns.fetch(:discussion_expanded, false)
- if discussions && !line.meta?
- discussion = discussions[line_code]
- if discussion
= render "discussions/diff_discussion", discussion: discussion, expanded: discussion_expanded
...@@ -5,15 +5,14 @@ ...@@ -5,15 +5,14 @@
%table.text-file.code.js-syntax-highlight{ data: diff_view_data, class: too_big ? 'hide' : '' } %table.text-file.code.js-syntax-highlight{ data: diff_view_data, class: too_big ? 'hide' : '' }
- last_line = 0 - last_line = 0
- diff_file.highlighted_diff_lines.each do |line| - discussions = @grouped_diff_discussions unless @diff_notes_disabled
- last_line = line.new_pos = render partial: "projects/diffs/line",
= render "projects/diffs/line", line: line, diff_file: diff_file collection: diff_file.highlighted_diff_lines,
as: :line,
- unless @diff_notes_disabled locals: { diff_file: diff_file,
- line_code = diff_file.line_code(line) discussions: discussions,
- discussion = @grouped_diff_discussions[line_code] if line_code plain: true }
- if discussion
= render "discussions/diff_discussion", discussion: discussion
- last_line = diff_file.highlighted_diff_lines.last.new_pos
- if !diff_file.new_file && last_line > 0 - if !diff_file.new_file && last_line > 0
= diff_match_line last_line, last_line, bottom: true = diff_match_line last_line, last_line, bottom: true
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