From 8be4b9073582d0d45692f84f46833e1c33de8a40 Mon Sep 17 00:00:00 2001 From: Ryan Lerch Date: May 31 2016 06:24:26 +0000 Subject: Do not render the diffs of large added and removed files Rendering large diffs in PRs is really slow. To counter this this commit does not render diffs for added and removed files that are over 100 lines, instead it provides a link to view the file. In the case of a removed file, it provides a link to the file as it was the before the commit. --- diff --git a/pagure/templates/pull_request.html b/pagure/templates/pull_request.html index 65b202a..523a9a6 100644 --- a/pagure/templates/pull_request.html +++ b/pagure/templates/pull_request.html @@ -280,6 +280,15 @@ {% else %} {% set patch_new_id = patch.new_oid %} {% endif %} + + {% if patch |hasattr('old_id') %} + {% set patch_old_id = patch.old_id %} + {% elif patch |hasattr('delta') %} + {% set patch_old_id = patch.delta.old_file.id %} + {% else %} + {% set patch_old_id = patch.old_oid %} + {% endif %} + {% if patch | hasattr('new_file_path') %} {% set patch_new_file_path = patch.new_file_path -%} {% if patch.new_file_path != patch.old_file_path %} @@ -316,23 +325,29 @@ {%endif%} {%endmacro%} - {% macro viewfilelink(filepath)%} + {% macro viewfilelink(filepath, identifier=False)%} {% if pull_request %} + {% if not identifier %} + {% set identifier = pull_request.branch_from %} + {% endif %} {{filepath}} @@ -406,14 +421,24 @@
empty file added
{% else %} - {% autoescape false %} - {{ patch | patch_to_diff | html_diff | format_loc( - filename=patch_new_file_path, - commit=patch_new_id, - prequest=pull_request, - index=loop.index, - tree_id=diff_commits[0].tree.id)}} - {% endautoescape %} + {% if patchtype == "added" and patch.line_stats[1] > 100 %} +
+
View the large added file {{ viewfilelink(patch_new_file_path) }}
+
+ {% elif patchtype == "removed" %} +
+
view the removed file {{ viewfilelink(patch_new_file_path, patch_old_id) }}
+
+ {% else %} + {% autoescape false %} + {{ patch | patch_to_diff | html_diff | format_loc( + filename=patch_new_file_path, + commit=patch_new_id, + prequest=pull_request, + index=loop.index, + tree_id=diff_commits[0].tree.id)}} + {% endautoescape %} + {% endif %} {% endif %}