#
Countless Extra
Paginate without the need of any count, saving one query per rendering.
If you don't need any frontend you should consider the Pagy::Keyset pagination that is even faster than countless, especially with big data
#
Setup
require 'pagy/extras/countless'
#
Modes
This extra uses the Pagy::Countless subclass internally. You can use it in two different modes by
enabling the :countless_minimal
variable (or not).
Your app needs a full classic pagination UI
#
Usage
@pagy, @records = pagy_countless(some_scope, ...)
This mode fetches limit + 1
and uses the number of fetched records to calculate the variables. It then removes the eventual
extra item from the result, so deducing whether there is a next
page or not without the need of an extra query.
- The
@records
collection is an eager-loadedArray
of records. - The
@pagy
object can be used with any supported helper.
Your app uses no or limited pagination UI
#
Set Up countless_minimal mode
require 'pagy/extras/countless'
# optionally enable the minimal mode by default
# Pagy::DEFAULT[:countless_minimal] = true
#
Usage
@pagy, @records = pagy_countless(some_scope, countless_minimal: true, ...)
This mode is enabled by the :countless_minimal
variable.
- The
@records
collection is a regular scope. - The
@pagy
object cannot be used with any helpers. - The collection is over when
@records.size < @pagy.limit
#
Variables
#
Methods
pagy_countless(collection, **vars)
This method is the same as the generic pagy
method (see the pagy doc), however
its returned objects will depend on the value of the :countless_minimal
variable (see
pagy_countless_get_items(collection, pagy)
This sub-method is similar to the pagy_get_items
sub-method, but it is called only by the pagy_countless
method. (see
the pagy_get_items doc).