summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaco Guzman <pacoguzmanp@gmail.com>2016-08-25 09:24:27 +0200
committerPaco Guzman <pacoguzmanp@gmail.com>2016-08-25 09:24:27 +0200
commitb3bdd9e8651df2d42abae9d2dae814e04d7c4642 (patch)
treea09780a46e4b12118ec4a7c16c285cb201c72d55
parentb2bf01f4c271be66e93ed6f4b48a1da4d50e558d (diff)
downloadgitlab-ce-diff-file-cache-html-content.tar.gz
DiffFile cache html rendered contentdiff-file-cache-html-content
-rw-r--r--app/helpers/diff_helper.rb17
-rw-r--r--app/views/projects/diffs/_content.html.haml9
-rw-r--r--app/views/projects/diffs/_text_file.html.haml1
3 files changed, 22 insertions, 5 deletions
diff --git a/app/helpers/diff_helper.rb b/app/helpers/diff_helper.rb
index 0725c3f4c56..1d72b019473 100644
--- a/app/helpers/diff_helper.rb
+++ b/app/helpers/diff_helper.rb
@@ -109,6 +109,23 @@ module DiffHelper
end
end
+ def diff_file_content_cacheable?(diff_file)
+ diff_file.diff_refs && !diff_file_will_show_discussions(diff_file)
+ end
+
+ def diff_file_will_show_discussions(diff_file)
+ return false if @diff_notes_disabled
+ return false unless @grouped_diff_discussions
+
+ @grouped_diff_discussions_by_file_path ||= @grouped_diff_discussions.values.flatten.group_by { |d| d.diff_file.file_path }
+ @grouped_diff_discussions_by_file_path.key?(diff_file.file_path)
+ end
+ private :diff_file_will_show_discussions
+
+ def diff_file_content_cache_key(diff_file, diff_view)
+ [diff_file.diff_refs.base_sha, diff_file.diff_refs.start_sha, diff_file.diff_refs.head_sha, diff_file.file_path, diff_view]
+ end
+
def diff_file_html_data(project, diff_file_path, diff_commit_id)
{
blob_diff_path: namespace_project_blob_diff_path(project.namespace, project,
diff --git a/app/views/projects/diffs/_content.html.haml b/app/views/projects/diffs/_content.html.haml
index d37961c4e40..8af44021cb4 100644
--- a/app/views/projects/diffs/_content.html.haml
+++ b/app/views/projects/diffs/_content.html.haml
@@ -13,10 +13,11 @@
.nothing-here-block.diff-collapsed{data: { diff_for_path: url } }
This diff is collapsed. Click to expand it.
- elsif diff_file.diff_lines.length > 0
- - if diff_view == :parallel
- = render "projects/diffs/parallel_view", diff_file: diff_file, project: project, blob: blob
- - else
- = render "projects/diffs/text_file", diff_file: diff_file
+ = cache_if(diff_file_content_cacheable?(diff_file), diff_file_content_cache_key(diff_file, diff_view), skip_digest: true) do
+ - if diff_view == :parallel
+ = render "projects/diffs/parallel_view", diff_file: diff_file
+ - else
+ = render "projects/diffs/text_file", diff_file: diff_file
- else
- if diff_file.mode_changed?
.nothing-here-block File mode changed
diff --git a/app/views/projects/diffs/_text_file.html.haml b/app/views/projects/diffs/_text_file.html.haml
index f1d2d4bf268..2a8bdc6916c 100644
--- a/app/views/projects/diffs/_text_file.html.haml
+++ b/app/views/projects/diffs/_text_file.html.haml
@@ -4,7 +4,6 @@
%a.show-suppressed-diff.js-show-suppressed-diff Changes suppressed. Click to show.
%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,