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

Sized enumerator #13938

Merged
merged 6 commits into from Feb 5, 2014
Merged

Sized enumerator #13938

merged 6 commits into from Feb 5, 2014

Conversation

@marcandre
Copy link
Contributor

@marcandre marcandre commented Feb 4, 2014

This PR adds a lazy size block to enumerators returned by Batches#find_each, find_in_batches, Result#each and Enumerable#index_by.

This allows, for example using my gem with_progress:

Users.where("balance > 0").find_each.with_progress do |u|
  UserMailer.send_invoice(u)
end

This will print a progress bar with an estimated time left, etc, while still loading the records in batches.

The PR also has a couple of test cleanup commits at the beginning.

Note: In Ruby 1.9, there is no Enumerator#size, so the test is conditional on that. The block given to to_enum is ignored in 1.9, so no specific treatment is needed.

@rafaelfranca
Copy link
Member

@rafaelfranca rafaelfranca commented Feb 4, 2014

@marcandre seems good to me. Could you squash the commits that add the feature? The two obsolete removals commits are good as separated commits.

We will need a CHANGELOG entry too.

@marcandre
Copy link
Contributor Author

@marcandre marcandre commented Feb 5, 2014

Right, forgot about the CHANGELOG, sorry. Done.
I feel the commits are independent and better left unsquashed. More detailed explanation here.

@rafaelfranca
Copy link
Member

@rafaelfranca rafaelfranca commented Feb 5, 2014

Thanks.

About the squash it is fine to me. I agree with you that they are independent.

rafaelfranca added a commit that referenced this pull request Feb 5, 2014
Sized enumerator
@rafaelfranca rafaelfranca merged commit 84fe7b7 into rails:master Feb 5, 2014
1 check was pending
1 check was pending
default The Travis CI build is in progress
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.