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

Improve support for sorting by a timestamp column #142

Merged
merged 5 commits into from
Oct 6, 2023

Conversation

aaronsama
Copy link
Contributor

@aaronsama aaronsama commented Oct 5, 2023

This PR uses #111 as a base to introduce a new type of cursor to be used when ordering by timestamp columns (e.g. created_at).

The paginator detects that the SQL type of order_by is a :datetime (here) and instantiates a new type of cursor that is able to correctly encode timestamps with the resolution of 1 microsecond.

This allows pagination to work correctly down to the smallest fraction supported by default.

Fixes #101 #92

@aaronsama aaronsama force-pushed the support_sorting_by_datetime branch 3 times, most recently from 180f828 to ef00cf5 Compare October 5, 2023 13:01
@aaronsama aaronsama marked this pull request as ready for review October 5, 2023 13:03
Copy link
Member

@nicolas-fricke nicolas-fricke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting this PR and for factoring in the changes done by
@xijo in #92 and @amandawraymond in #111 . I think having this in a separate cursor class should make maintenance and extensibility easier in future and having the cursor encode a number for the timestamp field should lead to more compact cursors than encoding an object with their own keys.

I've left a few comments, let me know if there are any questions on them and let's try to get this released soon 🙂

lib/rails_cursor_pagination/timestamp_cursor.rb Outdated Show resolved Hide resolved
lib/rails_cursor_pagination/timestamp_cursor.rb Outdated Show resolved Hide resolved
lib/rails_cursor_pagination/timestamp_cursor.rb Outdated Show resolved Hide resolved
spec/rails_cursor_pagination/paginator_spec.rb Outdated Show resolved Hide resolved
amandawraymond and others added 2 commits October 5, 2023 16:19
…rsors add spec coverage for timestamp order_by selector in pagination fetch

Bump version to 0.3.1
Merge the latest changes from master into this PR to "rebase" it and
avoid a force push.
aaronsama and others added 3 commits October 5, 2023 17:18
Add a new subclass of the `Cursor` class to encode/decode cursors using
a timestamp column (such as `created_at`) as order field. It encodes
the value of the field as a number with microsecond resolution (the
default for MySQL).

This cursor class is instantiated instead of the regular `Cursor` when
an `order_field` of a compatible type is used to configure the
paginator.
Apply suggestions to improve methods' documentation

Co-authored-by: Nicolas Fricke <1423331+nicolas-fricke@users.noreply.github.com>
@nicolas-fricke nicolas-fricke merged commit 30b5ace into master Oct 6, 2023
24 checks passed
@nicolas-fricke nicolas-fricke deleted the support_sorting_by_datetime branch October 6, 2023 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Duplicated item on next page when ordering by DateTimes
3 participants