]> source.dussan.org Git - redmine.git/commitdiff
Avoid N queries when displaying the issue list with custom fields.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 15 Oct 2013 16:38:17 +0000 (16:38 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 15 Oct 2013 16:38:17 +0000 (16:38 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@12223 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/issue_query.rb
app/models/query.rb

index 56ef9f08e2d3c0ab89df6a6f58d0d20286ace4c2..66f520d640a0db3504b745dfc4efbc1f51174f9d 100644 (file)
@@ -323,7 +323,7 @@ class IssueQuery < Query
   def issues(options={})
     order_option = [group_by_sort_order, options[:order]].flatten.reject(&:blank?)
 
-    issues = Issue.visible.
+    scope = Issue.visible.
       joins(:status, :project).
       where(statement).
       includes(([:status, :project] + (options[:include] || [])).uniq).
@@ -331,8 +331,13 @@ class IssueQuery < Query
       order(order_option).
       joins(joins_for_order_statement(order_option.join(','))).
       limit(options[:limit]).
-      offset(options[:offset]).
-      all
+      offset(options[:offset])
+
+    if has_custom_field_column?
+      scope = scope.preload(:custom_values)
+    end
+
+    issues = scope.all
 
     if has_column?(:spent_hours)
       Issue.load_visible_spent_hours(issues)
index ca04f29b5051c70a000fc732f193303527147ea6..7582d73bc2ea42ca51256bfb77acd1cec9a88c04 100644 (file)
@@ -449,6 +449,10 @@ class Query < ActiveRecord::Base
     column_names && column_names.include?(column.is_a?(QueryColumn) ? column.name : column)
   end
 
+  def has_custom_field_column?
+    columns.any? {|column| column.is_a? QueryCustomFieldColumn}
+  end
+
   def has_default_columns?
     column_names.nil? || column_names.empty?
   end