Patch #33431 » time_query_performace.patch
| app/models/query.rb | ||
|---|---|---|
|
filters and filters[field]
|
||
|
end
|
||
|
def has_filter_with_prefix?(prefix)
|
||
|
filters && filters.map(&:first).count { |f| f.start_with?("#{prefix}.")} > 0
|
||
|
end
|
||
|
def type_for(field)
|
||
|
available_filters[field][:type] if available_filters.has_key?(field)
|
||
|
end
|
||
| app/models/time_entry_query.rb | ||
|---|---|---|
|
end
|
||
|
def base_scope
|
||
|
TimeEntry.visible.
|
||
|
joins(:project, :user).
|
||
|
includes(:activity).
|
||
|
references(:activity).
|
||
|
left_join_issue.
|
||
|
where(statement)
|
||
|
scope = TimeEntry.visible.joins(:project, :user)
|
||
|
scope = scope.joins(:activity) if has_filter?('activity_id')
|
||
|
scope = scope.left_join_issue if has_filter_with_prefix?('issue')
|
||
|
scope.where(statement)
|
||
|
end
|
||
|
def results_scope(options={})
|
||
|
order_option = [group_by_sort_order, (options[:order] || sort_clause)].flatten.reject(&:blank?)
|
||
|
order_option << "#{TimeEntry.table_name}.id ASC"
|
||
|
base_scope.
|
||
|
order(order_option).
|
||
|
joins(joins_for_order_statement(order_option.join(',')))
|
||
|
scope = base_scope.
|
||
|
order(order_option).
|
||
|
joins(joins_for_order_statement(order_option.join(',')))
|
||
|
scope = scope.preload(:activity) if has_column?(:activity)
|
||
|
scope
|
||
|
end
|
||
|
# Returns sum of all the spent hours
|
||