Rails: will_paginate bar from calling #count ActiveRelation

When I pass will_paginate ActiveRelation, it always calls its #count method and gets into the database to find out the total number of elements. But this operation takes time, and my total number is already cached and ready. Can I pass this pre-calculated counter to will_paginate and stop it from getting into the database?

I tried the parameter :count , but it was passed to ActiveRecord as an option:

 active_relation.paginate(page: 2, per_page: 100, count: total_count) 

Thanks!:)

+6
source share
1 answer

Passing a cached account using :total_entries solves the problem:

 active_relation.paginate(page: 2, per_page: 100, total_entries: total_count) 
+10
source

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


All Articles