Sha256: 9621d770601d5eeabb8db8bbb88eaf0005408ef6eb293fa95c4a98000a514970

Contents?: true

Size: 579 Bytes

Versions: 4

Compression:

Stored size: 579 Bytes

Contents

module CohortScope
  class BigCohort < Cohort
    # Reduce constraints by removing them one by one and counting the results.
    #
    # The constraint whose removal leads to the highest record count is removed from the overall constraint set.
    def self.reduce_constraints(active_record, constraints)
      most_restrictive_constraint = constraints.keys.max_by do |key|
        conditions = CohortScope.conditions_for constraints.except(key)
        active_record.scoped.where(conditions).count
      end
      constraints.except most_restrictive_constraint
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cohort_scope-0.2.3 lib/cohort_scope/big_cohort.rb
cohort_scope-0.2.2 lib/cohort_scope/big_cohort.rb
cohort_scope-0.2.1 lib/cohort_scope/big_cohort.rb
cohort_scope-0.2.0 lib/cohort_scope/big_cohort.rb