DEV Community

Cover image for Rails ActiveRecord count, size and length, map and pluck

Rails ActiveRecord count, size and length, map and pluck

Dario Chuquilla on March 15, 2024

Here I want to share with you some best practices for daily query requirements to help you improve the server's memory usage. We’ll discuss when to...
Collapse
 
epigene profile image
Augusts Bautra • Edited

pluck is so fast because it sidesteps ActiveRecord object initialization, only doing a DB query and returning the values without wrapping them in a model object.
Sometimes, however, the model is needed, maybe we want to call a method on each instance. There find_each may come handy.