1
0
Fork 0
mirror of https://github.com/kaminari/kaminari.git synced 2022-11-09 13:44:37 -05:00

use the mongoid criteria length to cache the count of the collection per criteria

Fixes slow pagination into large mongoid collections as the criteria method didn't cache the count. ActionViewExtension#page_entries_info calls total_count 3 or 4 times (depending on execution path), slowing the view render.

http://mongoid.org/en/mongoid/docs/querying.html

Criteria#length, Also size. Get a count of persisted documents. After being called once for the criteria, will cache subsequent calls and not hit the database.
This commit is contained in:
Campbell Allen 2013-12-05 13:09:40 +00:00
parent b4bf763eb8
commit 3796e3071c

View file

@ -9,7 +9,7 @@ module Kaminari
end
def total_count #:nodoc:
embedded? ? unpage.count : count
embedded? ? unpage.length : length
end
private