Optimize associations loading on the issue list.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3072 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
71bc44a89d
commit
d84bd8edd8
|
@ -64,7 +64,7 @@ class IssuesController < ApplicationController
|
|||
@issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
|
||||
@issue_pages = Paginator.new self, @issue_count, limit, params['page']
|
||||
@issues = Issue.find :all, :order => [@query.group_by_sort_order, sort_clause].compact.join(','),
|
||||
:include => [ :assigned_to, :status, :tracker, :project, :priority, :category, :fixed_version ],
|
||||
:include => ([:status, :project, :priority] + @query.include_options),
|
||||
:conditions => @query.statement,
|
||||
:limit => limit,
|
||||
:offset => @issue_pages.current.offset
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class QueryColumn
|
||||
attr_accessor :name, :sortable, :groupable, :default_order
|
||||
attr_accessor :name, :sortable, :groupable, :default_order, :include_options
|
||||
include Redmine::I18n
|
||||
|
||||
def initialize(name, options={})
|
||||
|
@ -27,6 +27,7 @@ class QueryColumn
|
|||
self.groupable = name.to_s
|
||||
end
|
||||
self.default_order = options[:default_order]
|
||||
self.include_options = options[:include]
|
||||
end
|
||||
|
||||
def caption
|
||||
|
@ -48,6 +49,7 @@ class QueryCustomFieldColumn < QueryColumn
|
|||
self.groupable = custom_field.order_statement
|
||||
end
|
||||
self.groupable ||= false
|
||||
self.include_options = :custom_values
|
||||
@cf = custom_field
|
||||
end
|
||||
|
||||
|
@ -107,15 +109,15 @@ class Query < ActiveRecord::Base
|
|||
|
||||
@@available_columns = [
|
||||
QueryColumn.new(:project, :sortable => "#{Project.table_name}.name", :groupable => true),
|
||||
QueryColumn.new(:tracker, :sortable => "#{Tracker.table_name}.position", :groupable => true),
|
||||
QueryColumn.new(:tracker, :sortable => "#{Tracker.table_name}.position", :groupable => true, :include => :tracker),
|
||||
QueryColumn.new(:status, :sortable => "#{IssueStatus.table_name}.position", :groupable => true),
|
||||
QueryColumn.new(:priority, :sortable => "#{IssuePriority.table_name}.position", :default_order => 'desc', :groupable => true),
|
||||
QueryColumn.new(:subject, :sortable => "#{Issue.table_name}.subject"),
|
||||
QueryColumn.new(:author),
|
||||
QueryColumn.new(:assigned_to, :sortable => ["#{User.table_name}.lastname", "#{User.table_name}.firstname", "#{User.table_name}.id"], :groupable => true),
|
||||
QueryColumn.new(:assigned_to, :sortable => ["#{User.table_name}.lastname", "#{User.table_name}.firstname", "#{User.table_name}.id"], :groupable => true, :include => :assigned_to),
|
||||
QueryColumn.new(:updated_on, :sortable => "#{Issue.table_name}.updated_on", :default_order => 'desc'),
|
||||
QueryColumn.new(:category, :sortable => "#{IssueCategory.table_name}.name", :groupable => true),
|
||||
QueryColumn.new(:fixed_version, :sortable => ["#{Version.table_name}.effective_date", "#{Version.table_name}.name"], :default_order => 'desc', :groupable => true),
|
||||
QueryColumn.new(:category, :sortable => "#{IssueCategory.table_name}.name", :groupable => true, :include => :category),
|
||||
QueryColumn.new(:fixed_version, :sortable => ["#{Version.table_name}.effective_date", "#{Version.table_name}.name"], :default_order => 'desc', :groupable => true, :include => :fixed_version),
|
||||
QueryColumn.new(:start_date, :sortable => "#{Issue.table_name}.start_date"),
|
||||
QueryColumn.new(:due_date, :sortable => "#{Issue.table_name}.due_date"),
|
||||
QueryColumn.new(:estimated_hours, :sortable => "#{Issue.table_name}.estimated_hours"),
|
||||
|
@ -322,6 +324,10 @@ class Query < ActiveRecord::Base
|
|||
def group_by_statement
|
||||
group_by_column.groupable
|
||||
end
|
||||
|
||||
def include_options
|
||||
(columns << group_by_column).collect {|column| column && column.include_options}.flatten.compact.uniq
|
||||
end
|
||||
|
||||
def project_statement
|
||||
project_clauses = []
|
||||
|
|
|
@ -202,6 +202,15 @@ class QueryTest < ActiveSupport::TestCase
|
|||
assert q.groupable_columns.detect {|c| c.is_a? QueryCustomFieldColumn}
|
||||
end
|
||||
|
||||
def test_include_options
|
||||
q = Query.new
|
||||
q.column_names = %w(subject tracker)
|
||||
assert_equal [:tracker], q.include_options
|
||||
|
||||
q.group_by = 'category'
|
||||
assert_equal [:tracker, :category], q.include_options
|
||||
end
|
||||
|
||||
def test_default_sort
|
||||
q = Query.new
|
||||
assert_equal [], q.sort_criteria
|
||||
|
|
Loading…
Reference in New Issue