I'm paginating the following query with Kaminari (though I get similar results with will_paginate):
Person.joins([:locations=>:location_hour], :friends, :current_images).where(sql_conditions_string).page(params[:page]).per(10)
Everything works as expected but pagination adds a database call
SELECT COUNT(*) FROM 'people' INNER JOIN 'location_histories'...
it's calling count(*) on the whole query. This takes 1.3 seconds whereas the original query (including the exact same joins and .where conditions) takes only ~.5 seconds.
Is there a way for pagination to just use the count from the original query? That last database call is a big performance problem.
I'm on Rails 3.0.7.
Thanks!