Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update readme with time_precision issue #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ Geared Pagination uses the ordered attributes (in the above example, `created_at

Cursors encode the information Geared Pagination needs to query for the corresponding page’s records: the page number for choosing a page size, and the values of each of the ordered attributes (`created_at` and `id`).

Since 7.0.2, [Rails generate datetime columns with a default precision of 6](https://github.com/rails/rails/blob/v7.0.2.3/activerecord/CHANGELOG.md#rails-702-february-08-2022). But by default the time precision for JSON encoding is 3. It could lead to unexpected result. To fix this, you need to [change the value to 6](https://guides.rubyonrails.org/configuring.html#config-active-support-time-precision):

```ruby
ActiveSupport::JSON::Encoding.time_precision = 6
```

### When should I use cursor-based pagination?

Cursor-based pagination can outperform offset-based pagination when paginating deeply into a large number of records. DBs commonly execute queries with `OFFSET` clauses by counting past `OFFSET` records one at a time, so each page in offset-based pagination takes slightly longer to load than the last. With cursor-based pagination and an appropriate index, the DB can jump directly to the beginning of each page without scanning.
Expand Down