7

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!

NAD
  • 615
  • 1
  • 7
  • 20
  • Yeah i've just spotted this same issue, using Kaminari, in my own performance tuning. I can see the main query actually being called 4 times in various formats, with and without counts etc adding an additional ~2s to each page load. Digging further to see what i can find. Did you come to any conclusions with this? – Pete Mar 09 '12 at 16:44

0 Answers0