#Gearbox Extra
Automatically change the limit
depending on the page number.
Instead of generating all the pages with a fixed limit, the app can serve pages with an increasing number of records in order to speed things up for wild-browsing and improving the user experience.
You can set this up by simply setting the :gearbox_limit
variable to an array of integers. For example, you would set the gearbox_limit
to [10, 20, 40, 80]
to get page 1
with limit: 10
, page 2
with limit: 20
, page 3
with limit: 40
and all the other pages with limit: 80
.
The content of the array is not restricted neither in length nor in direction: you can pass any arbitrary sequence of integer you like, although it makes more sense to have an increasing progression of records.
#Interaction with other extras
Even after requiring this extra, the regular fixed pagination is still supported: you have just to temporarily disable gearbox
with gearbox_extra: false
in the instances that need the fixed pagination.
You can also use it in presence of the limit extra if you follow a simple logic. The gearbox
extra automatically handles the :limit
for each page, while the limit extra allows the client to explicitly request a specific limit
for the pages. That's why the limit extra takes priority over the gearbox
extra if both are enabled.
If you want to use the gearbox
in some instances, you can temporarily set limit_extra: false
and the gearbox
will be used instead. That is a common scenario when you use the limit extra in an API controller, while you want to use the gearbox
in an infinite scroll pagination in another controller.
#Caveats
- This extra cannot be used with
Pagy::Calendar::*
objects, which are paginated by period. - The search extras (
elasticserch_rails
,meilisearch
andsearchkick
) are based on storages with built-in linear pagination, which is inconsistent with thegearbox
.
#Synopsis
#Variables
#Methods
The gearbox
extra overrides the setup_limit_var
and the setup_pages_vars
methods in the Pagy
class. You don't have to use them directly.
#Credits
The idea behind this extra comes from the Geared Pagination.
The main differences are that Pagy is not tied to ActiveRecord
so it works in any environment... many many many times faster!