Class: Collavre::Creatives::FilterPipeline

Inherits:
Object
  • Object
show all
Defined in:
app/services/collavre/creatives/filter_pipeline.rb

Defined Under Namespace

Classes: Result

Constant Summary collapse

FILTERS =

필터 클래스 목록 - 순서대로 적용

[
  Filters::ProgressFilter,
  Filters::TagFilter,
  Filters::SearchFilter,
  Filters::CommentFilter,
  Filters::DateFilter,
  Filters::AssigneeFilter
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(user:, params:, scope:) ⇒ FilterPipeline

Returns a new instance of FilterPipeline.



22
23
24
25
26
# File 'app/services/collavre/creatives/filter_pipeline.rb', line 22

def initialize(user:, params:, scope:)
  @user = user
  @params = params
  @scope = scope
end

Instance Method Details

#any_filter_active?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'app/services/collavre/creatives/filter_pipeline.rb', line 48

def any_filter_active?
  FILTERS.any? { |klass| klass.new(params: params, scope: scope).active? }
end

#callObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/services/collavre/creatives/filter_pipeline.rb', line 28

def call
  matched_ids = apply_filters
  return empty_result if matched_ids.empty?

  # 조상 포함
  allowed_ids = resolve_ancestors(matched_ids)

  # O(1) 권한 필터링
  allowed_ids = filter_by_permission(allowed_ids)

  progress_map, overall = calculate_progress(allowed_ids, matched_ids)

  Result.new(
    matched_ids: matched_ids.to_set,
    allowed_ids: allowed_ids.map(&:to_s).to_set,
    progress_map: progress_map,
    overall_progress: overall
  )
end

#matched_idsObject

Public: the raw filter/search matches, skipping ancestor + progress resolution. Lets lightweight callers (the picker’s flat search) avoid the full-page work in #call when they only need the matched rows.



55
56
57
# File 'app/services/collavre/creatives/filter_pipeline.rb', line 55

def matched_ids
  apply_filters
end

#search_only_relationObject

Public: the search match as a relation, but only when the flat search is the sole active filter. Lets the picker order + window the matches in SQL (via a subquery) instead of plucking every id into Ruby. Returns nil when other filters are active — the matched set is then a Ruby intersection of several filters, which has no single-relation form, so callers must fall back to #matched_ids.



65
66
67
68
69
70
71
72
# File 'app/services/collavre/creatives/filter_pipeline.rb', line 65

def search_only_relation
  active = FILTERS
    .map { |klass| klass.new(params: params, scope: scope) }
    .select(&:active?)
  return nil unless active.size == 1 && active.first.is_a?(Filters::SearchFilter)

  active.first.matched_relation
end