From 0759212a447491d9b886eb489166518b57a9c169 Mon Sep 17 00:00:00 2001
From: Jean-Philippe Lang
Date: Tue, 1 May 2007 20:56:19 +0000
Subject: [PATCH] Added fragment caching for svn diffs.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@499 e93f8b46-1217-0410-a6f0-8f06a7374b81
---
app/controllers/repositories_controller.rb | 13 +++++++++----
app/views/repositories/diff.rhtml | 16 +++++++++-------
2 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb
index f961049be..badbf6ecb 100644
--- a/app/controllers/repositories_controller.rb
+++ b/app/controllers/repositories_controller.rb
@@ -17,6 +17,7 @@
require 'SVG/Graph/Bar'
require 'SVG/Graph/BarHorizontal'
+require 'digest/sha1'
class RepositoriesController < ApplicationController
layout 'base'
@@ -73,10 +74,14 @@ class RepositoriesController < ApplicationController
end
def diff
- @rev_to = params[:rev_to] || (@rev-1)
- type = params[:type] || 'inline'
- @diff = @repository.scm.diff(params[:path], @rev, @rev_to, type)
- show_error and return unless @diff
+ @rev_to = (params[:rev_to] && params[:rev_to].to_i > 0) ? params[:rev_to].to_i : (@rev - 1)
+ @diff_type = ('sbs' == params[:type]) ? 'sbs' : 'inline'
+
+ @cache_key = "repositories/diff/#{@repository.id}/" + Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}")
+ unless read_fragment(@cache_key)
+ @diff = @repository.scm.diff(@path, @rev, @rev_to, type)
+ show_error and return unless @diff
+ end
end
def stats
diff --git a/app/views/repositories/diff.rhtml b/app/views/repositories/diff.rhtml
index 31b42d4ab..b1cfa8b44 100644
--- a/app/views/repositories/diff.rhtml
+++ b/app/views/repositories/diff.rhtml
@@ -8,21 +8,22 @@
<% end %>
<% end %>
- <%= select_tag 'type', options_for_select([[l(:label_diff_inline), "inline"], [l(:label_diff_side_by_side), "sbs"]], params[:type]), :onchange => "if (this.value != '') {this.form.submit()}" %>
- <%= submit_tag l(:button_apply) %>
+ <%= select_tag 'type', options_for_select([[l(:label_diff_inline), "inline"], [l(:label_diff_side_by_side), "sbs"]], params[:type]), :onchange => "if (this.value != '') {this.form.submit()}" %>
<% end %>
+
+<% cache(@cache_key) do %>
<% @diff.each do |table_file| %>
-<% if params[:type] == 'sbs' %>
+<% if @diff_type == 'sbs' %>
- <%= l(:label_attachment) %>: <%= table_file.file_name %>
+ <%= table_file.file_name %>
|
- <%= l(:label_revision) %> <%= @rev %> |
- <%= l(:label_revision) %> <%= @rev_to %> |
+ @<%= @rev %> |
+ @<%= @rev_to %> |
@@ -50,7 +51,7 @@
- <%= l(:label_attachment) %>: <%= table_file.file_name %>
+ <%= table_file.file_name %>
|
@@ -83,6 +84,7 @@
<% end %>
<% end %>
+<% end %>
<% content_for :header_tags do %>
<%= stylesheet_link_tag "scm" %>
--
2.39.5