ActiveRecord slow_delete_all

Deletes taking to long, just take a break 🙂
(so replication can catch up/things get unblocked)

Only use save sql, there is no escapeing.

  class ActiveRecord::Base
    def self.slow_delete_all(condition)
      count = 0
      loop do
        result = ActiveRecord::Base.connection.send(:delete_sql, "delete from #{table_name} where #{condition} limit 10000")
        count += result
        break if result == 0
        sleep 1

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s