You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix pagination_total index option to prevent SELECT count(*) queries
The pagination_total option is supposed to prevent expensive SELECT
count(*) queries from being performed when viewing a resource's index
page.
However, while this option was hiding the display of the total number of
pages, it did not actually prevent the query from being performed.
There were two reasons:
In `#build_pagination`, the line:
`text_node paginate collection, options`
would trigger Kaminari to call `#total_pages` on the collection, which would
trigger the query:
```
def paginate(scope, options = {}, &block)
options[:total_pages] ||= options[:num_pages] || scope.total_pages
```
By passing in the `:total_pages` option, we short circuit this assignment
and avoid the query.
That fix was not sufficient. In `#page_entries_info`, the call
`collection.num_pages` also triggered a SELECT count(*). I re-arranged
the conditionals to avoid that call if `@display_total` is false, while
trying to keep the behavior the same.
0 commit comments