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

Fix for double cursor iteration, removed extraneous block binding. #25

Merged
merged 3 commits into from Dec 31, 2012

Conversation

Projects
None yet
2 participants
@cheald
Copy link
Member

cheald commented Oct 19, 2012

Remove extraneous &block binding, remove extraneous method calls via method aliasing, fix Query#all to collect documents as it iterates them, rather than invoking to_a on the cursor post-iteration

cheald added some commits Oct 19, 2012

Remove extraneous &block binding, remove extraneous method calls via …
…method aliasing, fix Query#all to collect documents as it iterates them, rather than invoking to_a on the cursor post-iteration
@cheald

This comment has been minimized.

Copy link
Member

cheald commented Oct 23, 2012

I've added a few more changes.

First, I changed #exists? to do a single-record find for _id, rather than count. If you are doing a count with any query parameters at all, mongo performs an O(n) scan of the entire collection. See the last post of https://groups.google.com/forum/?fromgroups=#!topic/mongodb-user/8aFNkJbtDF0

In the case of MongoMapper, the uniqueness validator uses #exists?, which performs a count with conditions for the field being validated. On a large collection, this can have a significant performance impact. In the cases where you're validating uniqueness on an indexed field, this technique should be a fair bit faster.

The final commit was simply to add a little sugar for #last - invoking it without a sort parameter adds a sort by _id descending. I've missed this for years, finally decided to do something about it. :)

@jnunemaker jnunemaker merged commit c7617a7 into mongomapper:master Dec 31, 2012

1 check passed

default The Travis build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment