Project

General

Profile

Patch #33431 » time_query_performace.patch

Alexander Meindl, 2020-05-11 13:47

View differences:

app/models/query.rb
692 692
    filters and filters[field]
693 693
  end
694 694

  
695
  def has_filter_with_prefix?(prefix)
696
    filters && filters.map(&:first).count { |f| f.start_with?("#{prefix}.")} > 0
697
  end
698

  
695 699
  def type_for(field)
696 700
    available_filters[field][:type] if available_filters.has_key?(field)
697 701
  end
app/models/time_entry_query.rb
142 142
  end
143 143

  
144 144
  def base_scope
145
    TimeEntry.visible.
146
      joins(:project, :user).
147
      includes(:activity).
148
      references(:activity).
149
      left_join_issue.
150
      where(statement)
145
    scope = TimeEntry.visible.joins(:project, :user)
146
    scope = scope.joins(:activity) if has_filter?('activity_id')
147
    scope = scope.left_join_issue if has_filter_with_prefix?('issue')
148
    scope.where(statement)
151 149
  end
152 150

  
153 151
  def results_scope(options={})
154 152
    order_option = [group_by_sort_order, (options[:order] || sort_clause)].flatten.reject(&:blank?)
155 153

  
156 154
    order_option << "#{TimeEntry.table_name}.id ASC"
157
    base_scope.
158
      order(order_option).
159
      joins(joins_for_order_statement(order_option.join(',')))
155
    scope = base_scope.
156
             order(order_option).
157
             joins(joins_for_order_statement(order_option.join(',')))
158

  
159
    scope = scope.preload(:activity) if has_column?(:activity)
160
    scope
160 161
  end
161 162

  
162 163
  # Returns sum of all the spent hours
(1-1/5)