Sha256: 7c50e21df5cd216362050cf8b5d87c17fd0c81ed85e5e382b2d204780dfe9d72
Contents?: true
Size: 810 Bytes
Versions: 6
Compression:
Stored size: 810 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(model, constraints) highest_count_after_removal = nil losing_key = nil constraints.keys.each do |key| test_constraints = constraints.except(key) count_after_removal = model.scoped.where(sanitize_constraints(model, test_constraints)).count if highest_count_after_removal.nil? or count_after_removal > highest_count_after_removal highest_count_after_removal = count_after_removal losing_key = key end end constraints.except losing_key end end end
Version data entries
6 entries across 6 versions & 1 rubygems