MONGOID-5391 - Add #pluck_each, extract out PluckEnumerator #5497
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Fixes MONGOID-5391
I'd like to humbly request this feature for reconsideration to be merged. A certain Mongoid maintainer of xmas past rejected this on the grounds that there are plans in MONGOID-5411 to make a feature which returns query raw results as a demongoized, field-name-aliased Hash. I fully support doing MONGOID-5411, however its timeline is unspecified (still in "Needs Triage" state), whereas this feature (
#pluck_each
) is ready to be used today. It yields a tremendous performance gain 🚀 and I've gotten a ton of mileage out of it in my app.I also feel that this feature is not mutually exclusive functionality-wise with MONGOID-5411. Although the API syntax of MONGOID-5411 is not yet defined, if you just want to pluck a single value, it will look something like
.only(:my_field).query_as_hash.each {|result| result[:my_field] }
whereas the same in this code can be done here far more tersely as.pluck_each(:my_field) {|value| ... }
Lastly, I think the extraction of PluckEnumerator in this PR is probably a stepping stone toward implementing MONGOID-5411. I'd be happy to add looking at MONGOID-5411 to my queue.
For reference, the previously closed PR including discussion is here: #5332