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: move find command building all into the find operation #2643

Merged
merged 1 commit into from
Dec 2, 2020

Conversation

mbroadst
Copy link
Member

One of the changes made in merging the core and native drivers was to merge the wire protocol methods for executing find operations. A vestigial piece of this was that the find command was being built in the wire protocol layer, rather than the operation layer. This patch teases these two apart, so that the query wire protocol method only creates and executes an OP_QUERY message, and the modern and legacy find commands are built in the find operation's definition itself.

NODE-2900

src/operations/find.ts Outdated Show resolved Hide resolved
@nbbeeken nbbeeken self-requested a review December 1, 2020 18:17
@mbroadst mbroadst force-pushed the NODE-2900/query-find-operation-merge branch from 6c723d3 to b66c07a Compare December 1, 2020 22:03
Copy link
Contributor

@emadum emadum left a comment

Choose a reason for hiding this comment

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

LGTM! A few small nits but nothing to hold up a merge


if (options.projection) {
let projection = options.projection;
if (projection && !Buffer.isBuffer(projection) && Array.isArray(projection)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (projection && !Buffer.isBuffer(projection) && Array.isArray(projection)) {
if (projection && Array.isArray(projection)) {

Nit: Shouldn't Array.isArray imply !Buffer.isBuffer?

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed


if (typeof options.limit === 'number') {
if (options.limit < 0) {
findCommand.limit = Math.abs(options.limit);
Copy link
Contributor

@emadum emadum Dec 1, 2020

Choose a reason for hiding this comment

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

Suggested change
findCommand.limit = Math.abs(options.limit);
findCommand.limit = -options.limit;

Nit: I'd guess using the - operator is faster than Math.abs when we know something is negative, but also probably a fairly negligible improvement. Also applies below in the options.batchSize < 0 condition.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed. I left two Math.abs in there where I felt it improved readability (Math.abs(batchSize) < Math.abs(limit) looks better than -batchSize < -limit IMO)

One of the changes made in merging the core and native drivers was
to merge the wire protocol methods for executing find operations.
A vestigial piece of this was that the find command was being
built in the wire protocol layer, rather than the operation layer.
This patch teases these two apart, so that the `query` wire
protocol method only creates and executes an `OP_QUERY` message,
and the modern and legacy find commands are built in the find
operation's definition itself.

NODE-2900
@mbroadst mbroadst force-pushed the NODE-2900/query-find-operation-merge branch from b66c07a to eb020e0 Compare December 2, 2020 14:34
@mbroadst mbroadst merged commit 58e4252 into master Dec 2, 2020
@mbroadst mbroadst deleted the NODE-2900/query-find-operation-merge branch December 2, 2020 20:07
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.

3 participants