Search code examples
ruby-on-railsrubyactiverecordreturnblock

Is it possible in rails (or elsewhere in ruby) to prevent a block from returning? Returning 50,000 records in an array takes a while


So I'm running a bit of logic through all of the 50,000+ records in my table (several actually, but we'll just address one here they're all the same operation) and marking boolean indicators:

ActiveRecord::Base.silence do
  CoreRevenue.where('core_revenues_usd IS NOT NULL').each do |c|
    c.ok = true
    c.save
  end
end

As you may have noticed, I've already "shut up" the database from outputting a bunch of SQL responses to the console, but there's always the big array dump at the end of the operation that can take sometimes as long as 5-10 seconds.

So I'm wondering if I can stop x where x = CoreRevenue.where('core_revenues_usd IS NOT NULL') from getting dumped after the operation is completed. Thanks.

equally 'exciting' would be an answer explaining why this is not possible due to some sort of lambda calculus computing thing or what have you


Solution

  • You can’t prevent a block from returning, but you can just return something else instead:

    ActiveRecord::Base.silence do
      CoreRevenue.where('core_revenues_usd IS NOT NULL').each do |c|
        c.ok = true
        c.save
      end
    
      nil
    end