Consider find_each for looping through Active Record associations - Andy Croll
04-Mar-2023 764
The standard method for enumerating through groups of objects, both through arrays in Ruby and through Active Record models in Rails, is each.However, if you are looping over a large amount of data, perhaps all the records for a model in order to backfill data, you can encounter severe memory and speed issues, both with loading and processing large volumes of records.You should consider the functionality provided by Active Record’s Batches. We’ll demonstrate using find_each.
Consider find_each for looping through Active Record associations - Andy Croll #ruby #rubydeveloper #rubyonrails #Consider #find_each #looping #through #Active #Record #associations #Croll #active #record https://rubyonrails.ba/link/consider-find_each-for-looping-through-active-record-associations-andy-croll