From 19abb2d9e98bc40b956ad8ca5321d6764e7a538d Mon Sep 17 00:00:00 2001 From: ste26054 Date: Mon, 28 Nov 2016 14:07:05 +0000 Subject: [PATCH] Fix cache issues when displaying/exporting issues with lots of custom fields --- app/helpers/application_helper.rb | 4 ++-- app/helpers/custom_fields_helper.rb | 6 +++--- app/helpers/issues_helper.rb | 4 ++-- app/helpers/queries_helper.rb | 4 ++-- app/views/users/show.html.erb | 2 +- lib/redmine/export/pdf/issues_pdf_helper.rb | 4 ++-- lib/redmine/field_format.rb | 5 +++-- 7 files changed, 15 insertions(+), 14 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 74c3f35..6248aa5 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -170,7 +170,7 @@ module ApplicationHelper end # Helper that formats object for html or text rendering - def format_object(object, html=true, &block) + def format_object(object, html=true, originator=nil, &block) if block_given? object = yield object end @@ -199,7 +199,7 @@ module ApplicationHelper object.visible? && html ? link_to_issue(object) : "##{object.id}" when 'CustomValue', 'CustomFieldValue' if object.custom_field - f = object.custom_field.format.formatted_custom_value(self, object, html) + f = object.custom_field.format.formatted_custom_value(self, object, html, originator) if f.nil? || f.is_a?(String) f else diff --git a/app/helpers/custom_fields_helper.rb b/app/helpers/custom_fields_helper.rb index 3f357ab..1a0bfee 100644 --- a/app/helpers/custom_fields_helper.rb +++ b/app/helpers/custom_fields_helper.rb @@ -120,8 +120,8 @@ module CustomFieldsHelper end # Return a string used to display a custom value - def show_value(custom_value, html=true) - format_object(custom_value, html) + def show_value(custom_value, html=true, originator=nil) + format_object(custom_value, html, originator) end # Return a string used to display a custom value @@ -138,7 +138,7 @@ module CustomFieldsHelper # displayed, with the custom field and the formatted value as arguments def render_custom_field_values(object, &block) object.visible_custom_field_values.each do |custom_value| - formatted = show_value(custom_value) + formatted = show_value(custom_value, true, object) if formatted.present? yield custom_value.custom_field, formatted end diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index db94832..bd61644 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -228,7 +228,7 @@ module IssuesHelper values.each_with_index do |value, i| css = "cf_#{value.custom_field.id}" m = (i < half ? :left : :right) - rows.send m, custom_field_name_tag(value.custom_field), show_value(value), :class => css + rows.send m, custom_field_name_tag(value.custom_field), show_value(value, true, issue), :class => css end end end @@ -318,7 +318,7 @@ module IssuesHelper end end issue.visible_custom_field_values(user).each do |value| - items << "#{value.custom_field.name}: #{show_value(value, false)}" + items << "#{value.custom_field.name}: #{show_value(value, false, issue)}" end items end diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb index 7ccb5b0..c6c5079 100644 --- a/app/helpers/queries_helper.rb +++ b/app/helpers/queries_helper.rb @@ -152,7 +152,7 @@ module QueriesHelper value.to_s(issue) {|other| link_to_issue(other, :subject => false, :tracker => false)}.html_safe, :class => value.css_classes_for(issue)) else - format_object(value) + format_object(value, true, issue) end end @@ -170,7 +170,7 @@ module QueriesHelper end def csv_value(column, object, value) - format_object(value, false) do |value| + format_object(value, false, object) do |value| case value.class.name when 'Float' sprintf("%.2f", value).gsub('.', l(:general_csv_decimal_separator)) diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 9bb5d66..56cb956 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -14,7 +14,7 @@ <% end %> <% @user.visible_custom_field_values.each do |custom_value| %> <% if !custom_value.value.blank? %> -
  • <%= custom_value.custom_field.name %>: <%= show_value(custom_value) %>
  • +
  • <%= custom_value.custom_field.name %>: <%= show_value(custom_value, true, @user) %>
  • <% end %> <% end %>
  • <%=l(:label_registered_on)%>: <%= format_date(@user.created_on) %>
  • diff --git a/lib/redmine/export/pdf/issues_pdf_helper.rb b/lib/redmine/export/pdf/issues_pdf_helper.rb index 75f63d2..c8f669f 100644 --- a/lib/redmine/export/pdf/issues_pdf_helper.rb +++ b/lib/redmine/export/pdf/issues_pdf_helper.rb @@ -70,7 +70,7 @@ module Redmine half = (issue.visible_custom_field_values.size / 2.0).ceil issue.visible_custom_field_values.each_with_index do |custom_value, i| - (i < half ? left : right) << [custom_value.custom_field.name, show_value(custom_value, false)] + (i < half ? left : right) << [custom_value.custom_field.name, show_value(custom_value, false, issue)] end if pdf.get_rtl @@ -350,7 +350,7 @@ module Redmine query.inline_columns.collect do |column| s = if column.is_a?(QueryCustomFieldColumn) cv = issue.visible_custom_field_values.detect {|v| v.custom_field_id == column.custom_field.id} - show_value(cv, false) + show_value(cv, false, issue) else value = issue.send(column.name) if column.name == :subject diff --git a/lib/redmine/field_format.rb b/lib/redmine/field_format.rb index 0347ca8..f3e70fa 100644 --- a/lib/redmine/field_format.rb +++ b/lib/redmine/field_format.rb @@ -174,8 +174,9 @@ module Redmine [] end - def formatted_custom_value(view, custom_value, html=false) - formatted_value(view, custom_value.custom_field, custom_value.value, custom_value.customized, html) + def formatted_custom_value(view, custom_value, html=false, originator=nil) + customized_obj = originator || custom_value.customized + formatted_value(view, custom_value.custom_field, custom_value.value, customized_obj, html) end def formatted_value(view, custom_field, value, customized=nil, html=false)