]> source.dussan.org Git - redmine.git/commitdiff
Improve custom fields list performance (#24587).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 13 Dec 2016 19:46:31 +0000 (19:46 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 13 Dec 2016 19:46:31 +0000 (19:46 +0000)
Patch by Thomas Löber.

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

app/controllers/custom_fields_controller.rb
app/views/custom_fields/_index.html.erb

index 26e9b044d15c13c882d081e2e7674e4dd62fef22..71e4394f51969a91c06350568ae1ef3781232db1 100644 (file)
@@ -28,6 +28,8 @@ class CustomFieldsController < ApplicationController
     respond_to do |format|
       format.html {
         @custom_fields_by_type = CustomField.all.group_by {|f| f.class.name }
+        @custom_fields_projects_count =
+          IssueCustomField.where(is_for_all: false).joins(:projects).group(:custom_field_id).count
       }
       format.api {
         @custom_fields = CustomField.all
index 7a5d372836c961e53a42ad7e692673d37a240eba..0a5ff3ee140195eeb007ca9fd08872602967d787 100644 (file)
@@ -18,7 +18,7 @@
       <td><%= checked_image custom_field.is_required? %></td>
       <% if tab[:name] == 'IssueCustomField' %>
       <td><%= checked_image custom_field.is_for_all? %></td>
-      <td><%= l(:label_x_projects, :count => custom_field.projects.count) if custom_field.is_a? IssueCustomField and !custom_field.is_for_all? %></td>
+      <td><%= l(:label_x_projects, :count => @custom_fields_projects_count[custom_field.id]) if custom_field.is_a? IssueCustomField and !custom_field.is_for_all? %></td>
       <% end %>
       <td class="buttons">
         <%= reorder_handle(custom_field, :url => custom_field_path(custom_field), :param => 'custom_field') %>