Class: CohortScope::BigCohort
- Defined in:
- lib/cohort_scope/big_cohort.rb
Constant Summary
Constants inherited from Cohort
Class Method Summary collapse
-
.reduce_constraints(active_record, constraints) ⇒ Object
Reduce constraints by removing them one by one and counting the results.
Methods inherited from Cohort
#+, #__getobj__, #__setobj__, #active_record, #any?, #as_json, create, #impossible!, #impossible?, #initialize, #inspect, #none?, #to_json, #where_value_nodes
Constructor Details
This class inherits a constructor from CohortScope::Cohort
Class Method Details
.reduce_constraints(active_record, constraints) ⇒ Object
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.
6 7 8 9 10 11 12 |
# File 'lib/cohort_scope/big_cohort.rb', line 6 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 |