I have noticed that when I use the construct...
ActiveRecordChild.find(:all).each do |record|
That it still returns the array of all records. With larger datasets
this can be murder on memory..
I was trying to do this with one of my migrations and my computer
choked after the migration had consumed 1.8GB of memory.
I ended up having to rewrite the migration as..
max = ActiveRecordChild.maximum(:id)
1.upto(max).each do |i|
if record = ActiveRecordChild.find_by_id(i)
What I would like to propose is having find accept a block like this.
ActiveRecordChild.find(:all) do |record|
where instead of even composing a array of ActiveRecord objects, it
would just pass in to the block each record as it gets it processed,
and then forget about it as soon as the block exits.
A possible additional feature might be to collect the results of the
block like a 'collect' call and possibly even omitting that when the
block returns something that evaluates as false ( false or nil ). Over
all however, I think for memory considerations, I would rather have
the form of find with a block return nothing, as if I really want to
collect the results, I can alwase push something to an array.