发布时间: 2020-08-13 01:41:00
参考: https://github.com/amatsuda/kaminari#paginating-without-issuing-select-count-query
kaminari的 paginate 方法, 会对整个 result list 进行判断, 看看它的 count是多少.
对于表的记录特别大的时候, (例如1个亿), 很耗时,大约几十秒.
这个时候, 就需要把count这个方法去掉.
原来的:
<%= paginate @trades %>
改成:
controller:
@trades = Trade.where....page(params[:page]).without_count
view:
<%= link_to_prev_page @trades, "前一页" %>
<%= link_to_next_page @trades, "后一页" %>
就可以了.
Back