Commit 42699720 authored by jplang's avatar jplang

Don't join all associations by default (#24865).

git-svn-id: https://svn.redmine.org/redmine/trunk@16221 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent dcfa39ca
......@@ -66,8 +66,7 @@ class IssuesController < ApplicationController
@issue_count = @query.issue_count
@issue_pages = Paginator.new @issue_count, @limit, params['page']
@offset ||= @issue_pages.offset
@issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
:order => sort_clause,
@issues = @query.issues(:order => sort_clause,
:offset => @offset,
:limit => @limit)
@issue_count_by_group = @query.issue_count_by_group
......@@ -402,7 +401,7 @@ class IssuesController < ApplicationController
sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
sort_update(@query.sortable_columns, 'issues_index_sort')
limit = 500
issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version])
issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1))
if (idx = issue_ids.index(@issue.id)) && idx < limit
if issue_ids.size < 500
@issue_position = idx + 1
......
......@@ -273,9 +273,9 @@ class IssueQuery < Query
limit(options[:limit]).
offset(options[:offset])
scope = scope.preload(:custom_values)
if has_column?(:author)
scope = scope.preload(:author)
scope = scope.preload([:tracker, :priority, :author, :assigned_to, :fixed_version, :category] & columns.map(&:name))
if has_custom_field_column?
scope = scope.preload(:custom_values)
end
issues = scope.to_a
......@@ -513,6 +513,21 @@ class IssueQuery < Query
if order_options.include?('authors')
joins << "LEFT OUTER JOIN #{User.table_name} authors ON authors.id = #{queried_table_name}.author_id"
end
if order_options.include?('users')
joins << "LEFT OUTER JOIN #{User.table_name} ON #{User.table_name}.id = #{queried_table_name}.assigned_to_id"
end
if order_options.include?('fixed_version')
joins << "LEFT OUTER JOIN #{Version.table_name} ON #{Version.table_name}.id = #{queried_table_name}.fixed_version_id"
end
if order_options.include?('category')
joins << "LEFT OUTER JOIN #{IssueCategory.table_name} ON #{IssueCategory.table_name}.id = #{queried_table_name}.category_id"
end
if order_options.include?('tracker')
joins << "LEFT OUTER JOIN #{Tracker.table_name} ON #{Tracker.table_name}.id = #{queried_table_name}.tracker_id"
end
if order_options.include?('enumeration')
joins << "LEFT OUTER JOIN #{IssuePriority.table_name} ON #{IssuePriority.table_name}.id = #{queried_table_name}.priority_id"
end
end
joins.any? ? joins.join(' ') : nil
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment