From 80b2e48b27bad4535e9fae727ef2b4437c61aa3e Mon Sep 17 00:00:00 2001 From: alexwais Date: Wed, 8 Apr 2015 01:33:13 +0200 Subject: [PATCH] fixes severe slowdown (#6) for Redmine 2.5.2 --- README.md | 2 +- init.rb | 2 +- .../issue_patch.rb | 9 +++-- .../issue_query_patch.rb | 37 ++++++++++--------- .../query_column_patch.rb | 2 +- 5 files changed, 28 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 81262a3..8958c52 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ The plugin was developed and tested with Redmine version 2.5.2. - Put the plugin folder into your Redmine's /plugin directory. -- Restart your Redmine. +- Restart Redmine. ###License diff --git a/init.rb b/init.rb index f690c21..1d4375d 100644 --- a/init.rb +++ b/init.rb @@ -27,7 +27,7 @@ name 'Redmine Workflow Hidden Fields plugin' author 'Alexander Wais, et al.' description "Provides a 'hidden' issue field permission for workflows" - version '0.1.2' + version '0.1.2.1' url 'https://github.com/alexwais/redmine_workflow_hidden_fields' author_url 'http://www.redmine.org/issues/12005' end diff --git a/lib/redmine_workflow_hidden_fields/issue_patch.rb b/lib/redmine_workflow_hidden_fields/issue_patch.rb index 0de2869..1581569 100644 --- a/lib/redmine_workflow_hidden_fields/issue_patch.rb +++ b/lib/redmine_workflow_hidden_fields/issue_patch.rb @@ -5,12 +5,15 @@ def self.included(base) base.class_eval do unloadable alias_method_chain :safe_attribute_names, :hidden + alias_method_chain :visible_custom_field_values, :hidden + alias_method_chain :read_only_attribute_names, :hidden + alias_method_chain :each_notification, :hidden end end module InstanceMethods - def visible_custom_field_values(user=nil) + def visible_custom_field_values_with_hidden(user=nil) user_real = user || User.current fields = custom_field_values.select do |value| value.custom_field.visible_by?(project, user_real) @@ -29,7 +32,7 @@ def viewable_custom_field_values(user=nil) end - def read_only_attribute_names(user=nil) + def read_only_attribute_names_with_hidden(user=nil) workflow_rule_by_attribute(user).reject {|attr, rule| rule != 'readonly' and rule != 'hidden'}.keys end @@ -46,7 +49,7 @@ def hidden_attribute?(name, user=nil) end - def each_notification(users, &block) + def each_notification_with_hidden(users, &block) if users.any? variations = users.collect { |user| (hidden_attribute_names(user) + (custom_field_values - visible_custom_field_values(user))).uniq diff --git a/lib/redmine_workflow_hidden_fields/issue_query_patch.rb b/lib/redmine_workflow_hidden_fields/issue_query_patch.rb index 8ec117e..c995c33 100644 --- a/lib/redmine_workflow_hidden_fields/issue_query_patch.rb +++ b/lib/redmine_workflow_hidden_fields/issue_query_patch.rb @@ -13,26 +13,27 @@ def self.included(base) module InstanceMethods def available_columns_with_hidden - - @available_columns = available_columns_without_hidden - - if project == nil - hidden_fields = [] - all_projects.each { |prj| - if prj.visible? and User.current.roles_for_project(prj).count > 0 - hidden_fields = hidden_fields == [] ? prj.completely_hidden_attribute_names : hidden_fields & prj.completely_hidden_attribute_names - end - } - else - hidden_fields = project.completely_hidden_attribute_names + unless @available_columns + @available_columns = available_columns_without_hidden + + if project == nil + hidden_fields = [] + all_projects.each { |prj| + if prj.visible? and User.current.roles_for_project(prj).count > 0 + hidden_fields = hidden_fields == [] ? prj.completely_hidden_attribute_names : hidden_fields & prj.completely_hidden_attribute_names + end + } + else + hidden_fields = project.completely_hidden_attribute_names + end + hidden_fields.map! {|field| field.sub(/_id$/, '')} + + @available_columns.reject! {|column| + hidden_fields.include?(column.name.to_s) + } end - hidden_fields.map! {|field| field.sub(/_id$/, '')} - - @available_columns.reject! {|column| - hidden_fields.include?(column.name.to_s) - } - @available_columns + @available_columns end def available_filters_with_hidden diff --git a/lib/redmine_workflow_hidden_fields/query_column_patch.rb b/lib/redmine_workflow_hidden_fields/query_column_patch.rb index f7d4fcf..ebe6ee7 100644 --- a/lib/redmine_workflow_hidden_fields/query_column_patch.rb +++ b/lib/redmine_workflow_hidden_fields/query_column_patch.rb @@ -10,7 +10,7 @@ def self.included(base) module InstanceMethods - def value_with_hidden(object) + def value_with_hidden(object) object.send name if object.respond_to?(:hidden_attribute_names) hidden_fields = object.hidden_attribute_names.map {|field| field.sub(/_id$/, '')}