Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/estimate_count.rb

Class Method Summary collapse

Class Method Details

.estimate_count(threshold: 1000) ⇒ Object



8
9
10
11
12
13
# File 'lib/estimate_count.rb', line 8

def self.estimate_count(threshold: 1000)
  full_scope = current_scope&.limit(nil)&.offset(nil) || all
  rows = estimate_rows(full_scope.to_sql)
  rows = full_scope.count if threshold.is_a?(Integer) && rows < threshold
  rows
end