Skip to content

Commit

Permalink
Improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Sep 28, 2024
1 parent d947e88 commit 19bff8e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions docs/api/keyset.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ less convenient for UIs.
| Term | Description |
|---------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `offset pagination` | Technique to fetch each page by changing the `offset` from the collection start.<br/>It requires two queries per page (or one if [countless](/docs/api/countless.md)): it's slow toward the end of big tables.<br/>It can be used for a rich frontend: it's the regular pagy pagination. |
| `keyset pagination` | Technique to fetch the next page starting from the `latest` fetched record in an `uniquely ordered` collection.<br/>It requires only one query per page: it's very fast regardless the table size and position (if properly indexed). It has a very limited usage in frontend. |
| `keyset pagination` | Technique to fetch the next page starting from the `latest` fetched record in an `uniquely ordered` collection.<br/>It requires only one query per page: it's very fast regardless the table size and position (if properly indexed). It has a very limited usage in frontend. |
| `uniquely ordered` | When the concatenation of the values of the ordered columns is unique for each record. It is similar to a composite primary `key` for the ordered table, but dynamically based on the `keyset` columns. |
| `set` | The `uniquely ordered` `ActiveRecord::Relation` or `Sequel::Dataset` collection to paginate. |
| `keyset` | The hash of column/direction pairs. Pagy extracts it from the order of the `set`. |
| `latest` | The hash of `keyset` attributes of the `latest` fetched record (from the latest page). Pagy decodes it from the `:page` variable, and uses it to filter out the already fetched records. |
| `latest` | The hash of `keyset` attributes of the `latest` fetched record (from the latest page). Pagy decodes it from the `:page` variable, and uses it to filter out the records already fetched. |
| `next` | The next `page`, i.e. the encoded reference to the last record of the **current page**. |
| `page` | The current `page`, i.e. the encoded reference to the `latest` record of the **latest page**. |

Expand Down Expand Up @@ -97,7 +97,8 @@ Depending on your order requirements, here is how you set it up:

+++ No order requirements
!!!success
If you don't need any ordering, `order(:id)` is the simplest choice, because it's unique and already indexed. It works fast out of the box without any setup.
If you don't need any ordering, `order(:id)` is the simplest choice, because it's unique and already indexed. It is fast out
of the box without any setup.
!!!

+++ Specific order requirements
Expand Down Expand Up @@ -239,7 +240,7 @@ They may have been stored as strings formatted differently than the default form
!!! Success

- Ensure that the composite index reflects exactly the columns sequence and order of your keyset
- Research about your specific DB features: type of index and performance for different ordering: use SQL `EXPLAIN ANALYZE`
- Research about your specific DB features, type of index and performance for different ordering. Use SQL `EXPLAIN ANALYZE`
or similar tool to confirm.
- Consider using the same direction order, enabling the `:tuple_comparison`, changing type of index (different DBs may behave
differently)
Expand Down
4 changes: 2 additions & 2 deletions docs/extras/keyset.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ set = Product.order(brand: :asc, model: :desc, id: :asc)
@pagy, @records = pagy_keyset(set, **vars)

# URL Helpers
pagy_keyset_first_url_page(@pagy, absolute: true)
pagy_keyset_first_url(@pagy, absolute: true)
#=> "http://example.com/foo?page"

pagy_keyset_next_url_page(@pagy)
pagy_keyset_next_url(@pagy)
#=> "/foo?page=eyJpZCI6MzB9"
```

Expand Down

0 comments on commit 19bff8e

Please # to comment.