-
Notifications
You must be signed in to change notification settings - Fork 12
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
Add a cursor for the current page. #43
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add to README.
Not for this PR, but I wonder whether we can make some of the cursor construction lazy to avoid paying the cost of the cursors being generated without being used.
lib/mongo/scrollable.rb
Outdated
iterator = Mongoid::Criteria::Scrollable::Iterator.new( | ||
previous_cursor: previous_cursor, | ||
next_cursor: cursor_type.from_record(record, cursor_options) | ||
next_cursor: cursor_type.from_record(record, cursor_options), | ||
current_cursor: current_cursor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some rubocop will be needed here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed, thanks.
Rubocop show me 138 offenses with the config in .rubocop.yml 😥
Co-authored-by: Daniel (dB.) Doubrovkine <[email protected]>
…ll into current-page-cursor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like CI failed for something legit.
The problem is that we have to build cursors with the first and the last record. We don't know how many records there are without an extra query. We can do :
But it means we converts records to an array, so we fetch documents first and I guess we will have other errors. |
Actually, we can have data about the records with |
Co-authored-by: Daniel (dB.) Doubrovkine <[email protected]>
I don't know why but I fixed it. |
#42 have to be merged first so I will change the Changelog and Readme in this PR. |
Thanks! Rebase? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something's odd in the README.
FYI, 2.0 has been released, https://twitter.com/dblockdotorg/status/1832420865847259391/ |
I added
current_cursor
toMongoid::Scroll::Scrollable::Iterator
.This allows to store the cursor and have the same result.
We use it to have this kind of payload for an API response :
Given that, we can find the same records if we do a call with the token related to the current cursor.