Feature #44364 » 0001-Preload-the-associations-rendered-by-the-issues-API-.patch
| app/controllers/issues_controller.rb | ||
|---|---|---|
| 58 | 58 |
format.api do |
| 59 | 59 |
@offset, @limit = api_offset_and_limit |
| 60 | 60 |
@query.column_names = %w(author) |
| 61 |
preload = [:tracker, :assigned_to, :category, :fixed_version, :custom_values] |
|
| 62 |
preload << :attachments if include_in_api_response?('attachments')
|
|
| 61 | 63 |
@issue_count = @query.issue_count |
| 62 |
@issues = @query.issues(:offset => @offset, :limit => @limit) |
|
| 64 |
@issues = @query.issues(:offset => @offset, :limit => @limit, :preload => preload)
|
|
| 63 | 65 |
Issue.load_visible_relations(@issues) if include_in_api_response?('relations')
|
| 64 | 66 |
if User.current.allowed_to?(:view_time_entries, nil, :global => true) |
| 65 | 67 |
Issue.load_visible_spent_hours(@issues) |
| app/models/issue_query.rb | ||
|---|---|---|
| 402 | 402 |
end |
| 403 | 403 |
# Returns the issues |
| 404 |
# Valid options are :order, :offset, :limit, :include, :conditions |
|
| 404 |
# Valid options are :order, :offset, :limit, :conditions, |
|
| 405 |
# :include, and :preload |
|
| 405 | 406 |
def issues(options={})
|
| 406 | 407 |
order_option = [group_by_sort_order, (options[:order] || sort_clause)].flatten.reject(&:blank?) |
| 407 | 408 |
# The default order of IssueQuery is issues.id DESC(by IssueQuery#default_sort_criteria) |
| ... | ... | |
| 424 | 425 |
[:tracker, :author, :assigned_to, :fixed_version, |
| 425 | 426 |
:category, :attachments] & columns.map(&:name) |
| 426 | 427 |
) |
| 428 |
if options[:preload] |
|
| 429 |
scope = scope.preload(options[:preload]) |
|
| 430 |
end |
|
| 427 | 431 |
if has_custom_field_column? |
| 428 | 432 |
scope = scope.preload(:custom_values) |
| 429 | 433 |
end |