Large Result Not Chunked (ARCH6062)
Key ruby.orm.large-result-not-chunked · Severity info · Category orm
Loading an entire large result set into memory then iterating pulls millions of rows at once when a streaming/chunk API like find_each exists.
Incorrect
Section titled “Incorrect”User.where(active: true).each do |user| Mailer.notify(user).deliver_later # whole result loaded into memoryendCorrect
Section titled “Correct”User.where(active: true).find_each(batch_size: 1000) do |user| Mailer.notify(user).deliver_laterendIterate large results in chunks with find_each/in_batches instead of loading them all into memory.