6
当我通过will_paginate
ActiveRelation,它总是调用其#count方法,并击中数据库找出项目的总数。但是这个操作需要时间,而且我已经将总数缓存并准备好了。我可以将这个预先计算的计数传递给will_paginate
并阻止其击中数据库吗?Rails:阻止will_paginate调用#的ActiveRelation
我试过:count
选择,但它传递给ActiveRecord的作为一个选项:
active_relation.paginate(page: 2, per_page: 100, count: total_count)
谢谢! :)