Will_paginate with mongoid (total_entries issue)

跟風遠走 提交于 2019-12-25 02:22:29

问题


When using mongoid with 'will_paginate' gem, it seems like method called 'total_entries' doesnt work which can affect perfomance


回答1:


So I was using Mongoid with 'will_paginate' gem and I had this problem with 'total_entries' option, and to be more specific, I dont think it was working at all, which is not very good for perfomance in many situations... After a while I found this gem but it didnt look like 'total_entries' method was working there so here's what I did:
1) Opened mongoid_paginator in will_paginate_mongoid location
2) Made a little fix, so it looked like this:

WillPaginate::Collection.create(options[:page], options[:per_page]) do |pager|
      items_count = options[:total_entries] || self.count
      fill_pager_with self.skip(options[:offset]).limit(options[:per_page]), items_count, pager

which I took from here and hallelujah, it works again, no more counts on every load.

Since I am a newbie I could make something foolish and I hope I will be corrected if so and hope it'll be helpful for somebody :)



来源:https://stackoverflow.com/questions/21823366/will-paginate-with-mongoid-total-entries-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!