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
This commit is contained in:
parent
758cc2f2e6
commit
3172359f97
|
@ -323,7 +323,7 @@ class IssueQuery < Query
|
||||||
def issues(options={})
|
def issues(options={})
|
||||||
order_option = [group_by_sort_order, options[:order]].flatten.reject(&:blank?)
|
order_option = [group_by_sort_order, options[:order]].flatten.reject(&:blank?)
|
||||||
|
|
||||||
issues = Issue.visible.
|
scope = Issue.visible.
|
||||||
joins(:status, :project).
|
joins(:status, :project).
|
||||||
where(statement).
|
where(statement).
|
||||||
includes(([:status, :project] + (options[:include] || [])).uniq).
|
includes(([:status, :project] + (options[:include] || [])).uniq).
|
||||||
|
@ -331,8 +331,13 @@ class IssueQuery < Query
|
||||||
order(order_option).
|
order(order_option).
|
||||||
joins(joins_for_order_statement(order_option.join(','))).
|
joins(joins_for_order_statement(order_option.join(','))).
|
||||||
limit(options[:limit]).
|
limit(options[:limit]).
|
||||||
offset(options[:offset]).
|
offset(options[:offset])
|
||||||
all
|
|
||||||
|
if has_custom_field_column?
|
||||||
|
scope = scope.preload(:custom_values)
|
||||||
|
end
|
||||||
|
|
||||||
|
issues = scope.all
|
||||||
|
|
||||||
if has_column?(:spent_hours)
|
if has_column?(:spent_hours)
|
||||||
Issue.load_visible_spent_hours(issues)
|
Issue.load_visible_spent_hours(issues)
|
||||||
|
|
|
@ -449,6 +449,10 @@ class Query < ActiveRecord::Base
|
||||||
column_names && column_names.include?(column.is_a?(QueryColumn) ? column.name : column)
|
column_names && column_names.include?(column.is_a?(QueryColumn) ? column.name : column)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def has_custom_field_column?
|
||||||
|
columns.any? {|column| column.is_a? QueryCustomFieldColumn}
|
||||||
|
end
|
||||||
|
|
||||||
def has_default_columns?
|
def has_default_columns?
|
||||||
column_names.nil? || column_names.empty?
|
column_names.nil? || column_names.empty?
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue