]> source.dussan.org Git - redmine.git/commitdiff
Speed up workflow edit page rendering (#31855).
authorGo MAEDA <maeda@farend.jp>
Sat, 17 Aug 2019 02:23:51 +0000 (02:23 +0000)
committerGo MAEDA <maeda@farend.jp>
Sat, 17 Aug 2019 02:23:51 +0000 (02:23 +0000)
Patch by Felix Schäfer.

git-svn-id: http://svn.redmine.org/redmine/trunk@18373 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/workflows_helper.rb
app/views/workflows/_form.html.erb

index c09310acdc23deed74f510a84899f69e9c0e573b..f9c545e5a353cf464195c120d2aebae206c9ff64 100644 (file)
@@ -74,8 +74,8 @@ module WorkflowsHelper
     select_tag("permissions[#{status.id}][#{name}]", options_for_select(options, selected), html_options)
   end
 
-  def transition_tag(workflows, old_status, new_status, name)
-    w = workflows.select {|w| w.old_status == old_status && w.new_status == new_status}.size
+  def transition_tag(transition_count, old_status, new_status, name)
+    w = transition_count
 
     tag_name = "transitions[#{ old_status.try(:id) || 0 }][#{new_status.id}][#{name}]"
     if old_status == new_status
index 542db4e3528e0c08a0d214306b10afeee429d19e..32639753c71591077d062aaebd8c71106adeb760 100644 (file)
@@ -21,6 +21,7 @@
     <% end %>
   </tr>
 </thead>
+<% transition_counts = workflows.each_with_object(Hash.new(0)) {|w,memo| memo[[w.old_status, w.new_status]] += 1} %>
 <tbody>
   <% for old_status in [nil] + @statuses %>
   <% next if old_status.nil? && name != 'always' %>
@@ -38,9 +39,9 @@
       <% end %>
     </td>
     <% for new_status in @statuses -%>
-    <% checked = (old_status == new_status) || workflows.detect {|w| w.old_status == old_status && w.new_status == new_status} %>
+    <% checked = (old_status == new_status) || (transition_counts[[old_status, new_status]] > 0) %>
     <td class="<%= checked ? 'enabled' : '' %>" title="<%= old_status_name %> &#187; <%= new_status.name %>">
-      <%= transition_tag workflows, old_status, new_status, name %>
+      <%= transition_tag transition_counts[[old_status, new_status]], old_status, new_status, name %>
     </td>
     <% end -%>
   </tr>