From 2f5c17a0f6eac2f50e61053e06672a1e83d4f598 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 14 Mar 2010 08:33:53 +0000 Subject: Optimization: load attachments when needed. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3581 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/helpers/application_helper.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'app/helpers') diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index ff877f18f..5663cc6d6 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -414,13 +414,11 @@ module ApplicationHelper only_path = options.delete(:only_path) == false ? false : true # when using an image link, try to use an attachment, if possible - attachments = options[:attachments] || (obj && obj.respond_to?(:attachments) ? obj.attachments : nil) - - if attachments - attachments = attachments.sort_by(&:created_on).reverse + if options[:attachments] || (obj && obj.respond_to?(:attachments)) + attachments = nil text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m| filename, ext, alt, alttext = $1.downcase, $2, $3, $4 - + attachments ||= (options[:attachments] || obj.attachments).sort_by(&:created_on).reverse # search for the picture in attachments if found = attachments.detect { |att| att.filename.downcase == filename } image_url = url_for :only_path => only_path, :controller => 'attachments', :action => 'download', :id => found @@ -592,6 +590,7 @@ module ApplicationHelper :class => (prefix == 'export' ? 'source download' : 'source') end when 'attachment' + attachments = options[:attachments] || (obj && obj.respond_to?(:attachments) ? obj.attachments : nil) if attachments && attachment = attachments.detect {|a| a.filename == name } link = link_to h(attachment.filename), {:only_path => only_path, :controller => 'attachments', :action => 'download', :id => attachment}, :class => 'attachment' -- cgit v1.2.3