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-6055): implement OnDemandDocument #4061

Merged
merged 19 commits into from
Apr 2, 2024

Conversation

nbbeeken
Copy link
Contributor

Description

What is changing?

  • Adds OnDemandDocument
    • getValue(), getNumber(), *valuesAs() toObject()
  • Adds StringFinder
    • caches strings as byte sequences
  • Add a new includes byte comparison method
Is there new documentation needed for these changes?

No

What is the motivation for this change?

OnDemandDocument will provide the foundation for doing less up front parsing work.

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

commit 7768782191e140b71dc33183fa6052dc4667a11a
Author: Neal Beeken <[email protected]>
Date:   Thu Mar 28 10:28:55 2024 -0400

    chore(NODE-XXXX): add getValue method to OnDemandDocument
package.json Outdated
@@ -26,7 +26,7 @@
},
"dependencies": {
"@mongodb-js/saslprep": "^1.1.5",
"bson": "^6.5.0",
"bson": "github:mongodb/js-bson#main",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As part of this review we can determine if we want anything moved to BSON, and I can fix the "this" issue with the NumberUtils, and we can put out a release and update this PR before merging it.

@nbbeeken nbbeeken changed the title chore(NODE-6055): Implement OnDemandDocument chore(NODE-6055): implement OnDemandDocument Mar 28, 2024
@baileympearson baileympearson self-assigned this Mar 29, 2024
@nbbeeken nbbeeken added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Mar 29, 2024
/** Caches the existence of a property */
private readonly existenceOf: Record<string, boolean> = Object.create(null);
/** Caches a look up of name to element */
private readonly elementOf: Record<string, BSONElement> = Object.create(null);
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't existenceOf[name] basically the same as elementOf[name] != null? do we need existenceOf?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not quite, if I look up a key that doesn't exist, I won't know of its non-existence until I get to the end of all the elements. Without this cache non-existence will look it up again.

src/utils.ts Outdated
@@ -1301,18 +1301,18 @@ export async function once<T>(ee: EventEmitter, name: string): Promise<T> {
}
}

export function maybeAddIdToDocuments(
coll: Collection,
export function maybeAddIdToDocuments<T extends Document>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this related to the work in this PR or just a nice improvement?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Accidentally left over from the PoC, we may want this at some point, but we can do it when necessary.

private readonly elements: BSONElement[];

/** The number of elements in the BSON document */
public readonly length: number;
Copy link
Contributor

Choose a reason for hiding this comment

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

numberOfElements?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd still lean toward size() here, but less is more, we can revist this if it is needed. For example, cursor might want to know how many docs are left but we should solve for that case.

Copy link
Contributor

@baileympearson baileympearson left a comment

Choose a reason for hiding this comment

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

Leaving some comments

@nbbeeken
Copy link
Contributor Author

mongodb/js-bson#665 Has BSON clean-up changes needed to get this branch off a git hash.

@W-A-James W-A-James self-requested a review April 1, 2024 14:25
@nbbeeken nbbeeken changed the title chore(NODE-6055): implement OnDemandDocument refactor(NODE-6055): implement OnDemandDocument Apr 1, 2024
W-A-James
W-A-James previously approved these changes Apr 1, 2024
@nbbeeken nbbeeken requested a review from baileympearson April 2, 2024 16:51
@baileympearson baileympearson merged commit cb5903f into main Apr 2, 2024
16 of 26 checks passed
@baileympearson baileympearson deleted the NODE-6055-on-demand branch April 2, 2024 22:23
aditi-khare-mongoDB pushed a commit that referenced this pull request Apr 5, 2024
baileympearson added a commit to baileympearson/node-mongodb-native that referenced this pull request Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Primary Review In Review with primary reviewer, not yet ready for team's eyes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants