Skip to content

Instantly share code, notes, and snippets.

@apeckham
Forked from sononum/gist:6183139
Created January 6, 2015 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apeckham/1d3c9e3602fc6e8e5885 to your computer and use it in GitHub Desktop.
Save apeckham/1d3c9e3602fc6e8e5885 to your computer and use it in GitHub Desktop.
# https://gist.github.com/sononum/6183139
module Kaminari
module ActiveRecordRelationMethods
def total_count_with_speed
if where_values_hash.empty?
sql = "SELECT (reltuples)::integer FROM pg_class r WHERE relkind = 'r' AND relname = #{self.connection.quote table_name}"
@_hacked_total_count || (@_hacked_total_count = self.connection.execute(sql).first["reltuples"].to_i)
else
total_count_without_speed
end
end
alias_method_chain :total_count, :speed
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment