Module: OptimizedIssuableLabelFilter

Defined in:
app/models/concerns/optimized_issuable_label_filter.rb

Instance Method Summary collapse

Instance Method Details

#by_label(items) ⇒ Object


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/models/concerns/optimized_issuable_label_filter.rb', line 4

def by_label(items)
  return items unless params.labels?

  return super if Feature.disabled?(:optimized_issuable_label_filter)

  target_model = items.model

  if params.filter_by_no_label?
    items.where('NOT EXISTS (?)', optimized_any_label_query(target_model))
  elsif params.filter_by_any_label?
    items.where('EXISTS (?)', optimized_any_label_query(target_model))
  else
    issuables_with_selected_labels(items, target_model)
  end
end

#count_by_stateObject

Taken from IssuableFinder


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/models/concerns/optimized_issuable_label_filter.rb', line 21

def count_by_state
  return super if root_namespace.nil?
  return super if Feature.disabled?(:optimized_issuable_label_filter)

  count_params = params.merge(state: nil, sort: nil, force_cte: true)
  finder = self.class.new(current_user, count_params)

  state_counts = finder
    .execute
    .reorder(nil)
    .group(:state_id)
    .count

  counts = state_counts.transform_keys { |key| count_key(key) }

  counts[:all] = counts.values.sum
  counts.with_indifferent_access
end