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

refactor(NODE-6201): cursor to use fetchBatch when current batch is empty #4093

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

nbbeeken
Copy link
Contributor

@nbbeeken nbbeeken commented Apr 22, 2024

Description

What is changing?

  • Move next into cursor and rename to fetchBatch
  • Remove transform and blocking flags
  • tryNext/next now call fetchBatch as appropriate to get the same behavior the flags provided
  • move cleanupCursor logic to cleanup()
Is there new documentation needed for these changes?

No

What is the motivation for this change?

The next floating function owned too many details of the implementation of each cursor API, tryNext and next now do a small amount more lifting and we have a fetchBatch method that is focused on obtaining the next batch either with the init command or with a getMore.

Double check the following

  • Ran npm run check:lint script
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

Comment on lines +526 to +540
if (
options?.error == null ||
options?.error?.name === 'MongoExpiredSessionError' ||
options?.force
) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without this change, endSession is sensitive to the exact order of endSession calls that were made by our cursor before this refactor.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you elaborate, and clarify why the ordering of endSessions calls changed?

@nbbeeken nbbeeken marked this pull request as ready for review May 1, 2024 18:39
@nbbeeken nbbeeken force-pushed the refactor-cursor-nextBatch branch 2 times, most recently from 29beee7 to 092ee7b Compare May 16, 2024 14:52
@W-A-James W-A-James added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Jun 4, 2024
@W-A-James W-A-James self-assigned this Jun 4, 2024
@nbbeeken nbbeeken changed the title refactor: cursor to use fetchBatch function when current batch is empty refactor(NODE-6201): cursor to use fetchBatch function when current batch is empty Jun 4, 2024
@nbbeeken nbbeeken requested a review from W-A-James June 5, 2024 17:10
@W-A-James W-A-James added Team Review Needs review from team and removed Primary Review In Review with primary reviewer, not yet ready for team's eyes labels Jun 5, 2024
W-A-James
W-A-James previously approved these changes Jun 5, 2024
Comment on lines +526 to +540
if (
options?.error == null ||
options?.error?.name === 'MongoExpiredSessionError' ||
options?.force
) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you elaborate, and clarify why the ordering of endSessions calls changed?

Comment on lines 806 to 807
// @ts-expect-error: not sure..
this.emit('close');
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're going to leave a ts-expect-error in, can we document why it's an error? but tbh I'd expect this to work, not sure why an expect error is needed here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes sorry meant to get back to this is is declared in the same way ConnectionEvents are so I'm not sure what is going on here.

Argument of type '[]' is not assignable to parameter of type 'Parameters<CursorEvents["close"]>'.ts(2345)

Maybe it is because CursorEvents is generic so Parameters<CursorEvents["close"]> may not be assignable to []. Not sure how to require extenders do not add parameters.

src/cursor/abstract_cursor.ts Outdated Show resolved Hide resolved
@nbbeeken nbbeeken changed the title refactor(NODE-6201): cursor to use fetchBatch function when current batch is empty refactor(NODE-6201): cursor to use fetchBatch when current batch is empty Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team Review Needs review from team
Projects
None yet
3 participants