jnunemaker/mongomapper — pull request #467 by cheald (2012-10-19 12:31:31+00:00)
Title: Performance improvements for IdentityMap

IDMap currently iterates every cursor *twice* if you call #all on an ID-mapped document, due to calling `IDMap#all`, super to `Plucky#all`, which invokes `IDMap#find_each`, which walks and then rewinds the cursor, then calling `Plucky#to_a`, which walks the cursor *again*. This effectively doubles the time spent for any #all query.

I fixed that by avoiding the `super` call to `Plucky::Query#all`, instead just collecting the documents as they're walked by `#find_each`.

Additionally, I removed an extraneous &block binding, which is about twice as slow as using an implicit block, since it actually has to create a Proc with the block binding.

Finally, I removed extraneous method calls and array creating by simply calling `doc.remove_from_identity_map` rather than `remove_documents_from_map(doc)` when doc is known to be a single record.

All tests pass.