Kaminari (or any pagination) is slower on the input request

I am processing the following request with Kaminari (although 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 calls a counter (*) for the whole request. This takes 1.3 seconds, while the original request (including the same connections and .where conditions) takes only ~ 0.5 seconds.

Is there a way for pagination to just use the counter from the original request? This last database call is a big performance issue.

I am on Rails 3.0.7.

Thanks!

+6
source share

Source: https://habr.com/ru/post/887954/


All Articles