Gem Pagy - 比 Kaminari 快五百多倍的分頁處理插件

Aiken00 · 2018年05月25日 · 最后由 stargwq 回复于 2018年06月14日 · 4517 次阅读

現在 Gem 也開始比速度了嗎。。。


Straightforward code

Pagy is just ~100 lines of simple ruby, organized in 3 flat modules very easy to understand and use it produces its own HTML, URLs, pluralization and interpolation with its own specialized and fast code 100% of its methods are public API, accessible and overridable right where you use them (no need of monkey patching or subclassing) Totally agnostic

it doesn't need to know anything about your models, ORM or Storage, so it doesn't add any code to them it works with all kinds of collections, even pre-paginated, records, Arrays, JSON data... and just whatever you can count it works with all Rack frameworks (Rails, Sinatra, Padrino, ecc.) out of the box it works with any possible non-Rack environment by just overriding one or two one-liner methods Easy to use

You can use pagy in a quite familiar way:

Paginate your collection in some controller:

@pagy, @records = pagy(Product.some_scope) Render the navigation links with a super-fast helper in some view:

<%== pagy_nav(@pagy) %> Or - if you prefer - render the navigation links with a template:

<%== render 'pagy/nav', locals: {pagy: @pagy} %>

感覺上這個可以用在 Ruby China .....

但我很想知道在什麼情況下 分頁處理 會是 樽頸......

ksec 回复

差別不大 純粹追求更快罷了

ksec 回复

瓶颈应该是数据量较大的时候,分页导致的 Count SQL 可能比较慢的问题

👍 放在项目试试

需要 登录 后方可回复, 如果你还没有账号请 注册新账号