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

Implemented $bitsAllClear, $bitsAllSet, $bitsAnyClear, $bitsAnySet in minimongo #8350

Merged
merged 5 commits into from
Mar 1, 2017

Conversation

davidworkman9
Copy link
Contributor

@davidworkman9 davidworkman9 commented Feb 10, 2017

Mongo supports this with Numbers and binData. I need to implement the latter still. Wanted to get some feedback and some advice on how to write some tests. The test file for minimongo is fairly overwhelming.

Edit:

Got buffers working, I think. One thing I'm unsure of is if Mongo will ever pass back anything other than a Uint8Array (like a Uint16Array for example). I get the feeling it doesn't, if I try to directly insert an instance of a Uint16Array when I query it back get a POJO.

@abernix
Copy link
Contributor

abernix commented Feb 13, 2017

Looking pretty good! ...and it looks like you've figured out (most) tests? If you need help specifically with anything, please do tell! 😄

@davidworkman9
Copy link
Contributor Author

I think I got it! I need to support buffers as a query parameter, which caused me to rewrite how I approached this completely. Pretty close now though. Should be done tomorrow.

@davidworkman9
Copy link
Contributor Author

I think this is ready now.

Copy link
Contributor

@benjamn benjamn left a comment

Choose a reason for hiding this comment

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

Thanks for working on this!

Since minimogo runs on the client, it contributes to the initial bundle size, so shorter code is better. Also, avoiding repetition makes code generally easier to maintain.

}) === 'undefined';
};
}
},
Copy link
Contributor

Choose a reason for hiding this comment

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

There seems to be a fair bit of duplicated code between these methods. Can you factor some of that out into helper functions? For example, this expression is repeated verbatim:

_.filter(operand, function (op, i) {
  var bitsSetOp = get8BitsSet(op);
  var bitsSetVal = get8BitsSet(value[i]);

  return typeof _.find(bitsSetOp, function (bit) {
    return bitsSetVal.indexOf(bit) !== -1;
  }) !== 'undefined';
})

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's actually not repeated, they're all slightly different, (e.g. !== vs ===). It was really hard to wrap my head around what it's doing. I'll take a stab at reducing it even further. Ability to use ES6 would go along way ;)

Copy link
Contributor

Choose a reason for hiding this comment

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

You should be able to use more modern ECMAScript in this file as ecmascript is included in its package.js


for ( var index = 0; index < byteArray.length; index ++ ) {
var byte = number & 0xff;
byteArray [ index ] = byte;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove the extra spaces here.

operand = ensureOperandUint8Array(operand);

if (!(value instanceof Uint8Array))
value = convertNumberToUint8Array(value);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you change this to something like ensureUint8Array and push the instanceof check into the function, rather than doing it multiple times in each method?

@davidworkman9
Copy link
Contributor Author

Is this better?

@abernix abernix added this to the Release 1.4.3.x milestone Mar 1, 2017
@abernix abernix merged commit 1fe3193 into meteor:devel Mar 1, 2017
@abernix
Copy link
Contributor

abernix commented Mar 1, 2017

Looks good! Thanks, @davidworkman9.

@abernix abernix modified the milestones: Release 1.4.3.x, Release 1.4.3.2 Mar 9, 2017
@yuwiggin
Copy link

I tested these bits operations, but only $bitAllSet succeeded, others failed: didn't return matched results to $bitsAllSet, $bitsAnyClear, $bitsAnySet.

The test environment:
Meteor: 1.8.1
mongo: 4.0.12

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

4 participants