From 3172359f9704d7c97adc60883d9ca5ec076c7667 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Tue, 15 Oct 2013 16:38:17 +0000 Subject: Avoid N queries when displaying the issue list with custom fields. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@12223 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/issue_query.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'app/models/issue_query.rb') diff --git a/app/models/issue_query.rb b/app/models/issue_query.rb index 56ef9f08e..66f520d64 100644 --- a/app/models/issue_query.rb +++ b/app/models/issue_query.rb @@ -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) -- cgit v1.2.3