This blog is part of our Rails 5.1 series.
Before Rails 5.1, we were not able to limit the number of records fetched in batch processing.
Let’s take an example. Assume our system has 20 users.
The above code will print ids of all the 20 users.
There was no way to limit
the number of records.
didn’t work for batches.
The above code still prints ids of all 20 users, even though the intention was to limit the records fetched to 10.
Rails 5.1 has added support to limit the records in batch processing.
The above code will print only 10 ids in Rails 5.1.
We can make use of limit