Skip to content

Files

Latest commit

 

History

History
28 lines (18 loc) · 892 Bytes

Rails-FindEach.md

File metadata and controls

28 lines (18 loc) · 892 Bytes

Pattern: Use of each instead of find_each

Issue: -

Description

This rule is used to identify usages of each and change them to use find_each instead. Looping through a collection of records from the database (using the all method, for example) is very inefficient since it will try to instantiate all the objects at once. In that case, batch processing methods allow you to work with the records in batches, thereby greatly reducing memory consumption.

Examples

# bad
User.all.each

# good
User.all.find_each

Default configuration

Attribute Value
Include app/models/**/*.rb

Further Reading