From 47b4a1befb5d8f2736e8e5d00f3f04c79d8ec323 Mon Sep 17 00:00:00 2001 From: Paco Guzman Date: Tue, 23 Aug 2016 06:59:42 +0200 Subject: WIP Cache diff_file diffs content TODO - some variations missing (plain and email) --- app/views/projects/diffs/_file.html.haml | 30 ++++++++++++++++++++++- app/views/projects/diffs/_line.html.haml | 8 ++---- app/views/projects/diffs/_parallel_view.html.haml | 7 +++--- app/views/projects/diffs/_text_file.html.haml | 3 +-- 4 files changed, 35 insertions(+), 13 deletions(-) diff --git a/app/views/projects/diffs/_file.html.haml b/app/views/projects/diffs/_file.html.haml index ad2eb3e504f..4e60ebc6745 100644 --- a/app/views/projects/diffs/_file.html.haml +++ b/app/views/projects/diffs/_file.html.haml @@ -16,4 +16,32 @@ = view_file_btn(diff_commit.id, diff_file.new_path, project) - = render 'projects/diffs/content', diff_file: diff_file, diff_commit: diff_commit, blob: blob, project: project + - cache_key = [diff_file.diff_refs.base_sha, diff_file.diff_refs.start_sha, diff_file.diff_refs.head_sha, diff_file.file_path, diff_view] + - content_html = Rails.cache.fetch(cache_key) do + - render 'projects/diffs/content', diff_file: diff_file, diff_commit: diff_commit, blob: blob, project: project + + - unless @diff_notes_disabled + - if discussions = @grouped_diff_discussions + - discussions = discussions.values.flatten.group_by { |d| d.diff_file.file_path } if discussions + - discussions = discussions[diff_file.file_path] if discussions + - if discussions + - if diff_view == :inline + - discussions.each do |discussion| + - discussion_html = render "discussions/diff_discussion", discussion: discussion, expanded: true + - content_html.sub!(//, discussion_html) + - elsif diff_view == :parallel + - diff_file.parallel_diff_lines.each do |line| + - left = line[:left] + - right = line[:right] + - if left || right + - discussions.each do |_discussion| + - discussion_left, discussion_right = parallel_diff_discussions(left, right, diff_file) + - if discussion_left || discussion_right + - # Delete already rendered discussion from the original collection + - @grouped_diff_discussions.delete(discussion_left.try(:line_code)) + - @grouped_diff_discussions.delete(discussion_right.try(:line_code)) + - discussion_html = render "discussions/parallel_diff_discussion", discussion_left: discussion_left, discussion_right: discussion_right + - content_html.sub!(//, discussion_html) + + - content_html.gsub!(//, '') + =raw content_html diff --git a/app/views/projects/diffs/_line.html.haml b/app/views/projects/diffs/_line.html.haml index 7042e9f1fc9..8564baf19a3 100644 --- a/app/views/projects/diffs/_line.html.haml +++ b/app/views/projects/diffs/_line.html.haml @@ -29,9 +29,5 @@ - else = diff_line_content(line.text, type) -- discussions = local_assigns.fetch(:discussions, nil) -- if discussions && !line.meta? - - discussion = discussions[line_code] - - if discussion - - discussion_expanded = local_assigns.fetch(:discussion_expanded, discussion.expanded?) - = render "discussions/diff_discussion", discussion: discussion, expanded: discussion_expanded + / + = "inject discussions #{line_code}" diff --git a/app/views/projects/diffs/_parallel_view.html.haml b/app/views/projects/diffs/_parallel_view.html.haml index 28aad3f4725..8fa2d8b4a74 100644 --- a/app/views/projects/diffs/_parallel_view.html.haml +++ b/app/views/projects/diffs/_parallel_view.html.haml @@ -33,9 +33,8 @@ %td.old_line.diff-line-num.empty-cell %td.line_content.parallel - - unless @diff_notes_disabled - - discussion_left, discussion_right = parallel_diff_discussions(left, right, diff_file) - - if discussion_left || discussion_right - = render "discussions/parallel_diff_discussion", discussion_left: discussion_left, discussion_right: discussion_right + - if left_line_code || right_line_code + / + = "inject discussions #{left_line_code} | #{right_line_code}" - if !diff_file.new_file && last_line > 0 = diff_match_line last_line, last_line, bottom: true, view: :parallel diff --git a/app/views/projects/diffs/_text_file.html.haml b/app/views/projects/diffs/_text_file.html.haml index f1d2d4bf268..2f597ebd1a4 100644 --- a/app/views/projects/diffs/_text_file.html.haml +++ b/app/views/projects/diffs/_text_file.html.haml @@ -5,11 +5,10 @@ %table.text-file.code.js-syntax-highlight{ data: diff_view_data, class: too_big ? 'hide' : '' } - last_line = 0 - - discussions = @grouped_diff_discussions unless @diff_notes_disabled = render partial: "projects/diffs/line", collection: diff_file.highlighted_diff_lines, as: :line, - locals: { diff_file: diff_file, discussions: discussions } + locals: { diff_file: diff_file } - last_line = diff_file.highlighted_diff_lines.last.new_pos - if !diff_file.new_file && last_line > 0 -- cgit v1.2.1