Skip to content

Prevent discrepancy between the original sort and the cursor sort #30

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

Merged

Conversation

FabienChaynes
Copy link
Collaborator

As seen in #28 (comment) (2c.), we want to prevent discrepancies between the cursor sort options and the original sort options.

This PR raises a new Mongoid::Scroll::Errors::DifferentSortFieldsError in case of mismatch:

[1] pry(main)> cursor = Mongoid::Scroll::Cursor.from_record(Feed::Item.first, { field: Feed::Item.fields['_id'] })
=> #<Mongoid::Scroll::Cursor:0x000055dfe8ffe588
 @direction=1,
 @field_name="_id",
 @field_type="BSON::ObjectId",
 @tiebreak_id=BSON::ObjectId('541014e17aa58d8ccf000025'),
 @value=BSON::ObjectId('541014e17aa58d8ccf000025')>

[2] pry(main)> Feed::Item.desc(:created_at).scroll(cursor)
Mongoid::Scroll::Errors::DifferentSortFieldsError: 

It was inspired from raise_multiple_sort_fields_error if multiple_sort_fields?.

Copy link
Collaborator Author

@FabienChaynes FabienChaynes left a comment

Choose a reason for hiding this comment

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

I'll add the same mechanism to the other *::Scrollable classes once we'll agree on an implementation for Mongoid::Criteria::Scrollable.

Copy link
Collaborator

@dblock dblock left a comment

Choose a reason for hiding this comment

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

This LGTM.

A possibly better word than "different" is "mismatched", I think it's more idiomatic. Up to you.

Please also update README describing what happens in this case, CHANGELOG and UPGRADING.md.

Pick whether you think this is a breaking change or a fix, and either increment the minor version or the major version as part of this PR.

@FabienChaynes FabienChaynes changed the title [WIP] Prevent discrepancy between the original sort and the cursor sort Prevent discrepancy between the original sort and the cursor sort Feb 24, 2023
@FabienChaynes
Copy link
Collaborator Author

Ready for a new round of review, feel free to update any wording!

@FabienChaynes FabienChaynes requested a review from dblock February 24, 2023 01:00
Copy link
Collaborator

@dblock dblock left a comment

Choose a reason for hiding this comment

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

Almost there.

@FabienChaynes FabienChaynes requested a review from dblock February 24, 2023 10:55
Copy link
Collaborator

@dblock dblock left a comment

Choose a reason for hiding this comment

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

LGTM, needs a rebase

@FabienChaynes FabienChaynes force-pushed the prevent-criteria-cursor-discrepancy branch from a77c52c to cebf579 Compare February 25, 2023 12:45
@FabienChaynes FabienChaynes requested a review from dblock February 25, 2023 13:09
@dblock dblock merged commit 587ef73 into mongoid:master Feb 25, 2023
@dblock
Copy link
Collaborator

dblock commented Feb 25, 2023

👍 merged

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.

None yet

2 participants