summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaco Guzman <pacoguzmanp@gmail.com>2016-08-23 06:59:42 +0200
committerPaco Guzman <pacoguzmanp@gmail.com>2016-08-23 08:50:22 +0200
commit47b4a1befb5d8f2736e8e5d00f3f04c79d8ec323 (patch)
treecfe33bc02c4b3e24ef11aa1ee27c26a7eea13f0f
parent5c7bca339bdb3c1b32ccea9d39d0789a949bca19 (diff)
downloadgitlab-ce-cache_diff_file_diffs_content.tar.gz
WIP Cache diff_file diffs contentcache_diff_file_diffs_content
TODO - some variations missing (plain and email)
-rw-r--r--app/views/projects/diffs/_file.html.haml30
-rw-r--r--app/views/projects/diffs/_line.html.haml8
-rw-r--r--app/views/projects/diffs/_parallel_view.html.haml7
-rw-r--r--app/views/projects/diffs/_text_file.html.haml3
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!(/<!--\ninject discussions #{discussion.line_code}\n-->/, 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!(/<!--\ninject discussions\s#{discussion_left.try(:line_code) || '.*'}\s\|\s#{discussion_right.try(:line_code) || '.*'}\n-->/, discussion_html)
+
+ - content_html.gsub!(/<!--\ninject discussions\s.*\n-->/, '')
+ =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