Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

31 lines (15 sloc) 0.919 kB
ever tried to destroy/delete tens of millions of rows at once? w/ rails it sucks, this tries to make it better
class Shredder < ActiveRecord::Base
has_many :beers
end
The default is 500 rows at a time, feel free to change it.
Shredder.destroy_amount = 2000 # woah, easy
Now your regular rails destroy methods will only destroy/delete destroy_amount at a time.
Shredder.destroy_all # instantiates x at a time, destroys one a time (no more instantiating the entire table ZOMG)
Shredder.delete_all # just deletes x at a time straight w/ SQL, this way you won't lock up the db with your giant locking query (what a jerk)
and in case you use acts_as_paranoid, it works with that too (destroy_all!)
last thing, it works on associations too, like so:
shredder = Shredder.find(:first)
shredder.beers.destroy_all # this is what shredders do
And it works on your :dependent => :destroy associations too.
SHRED!
Jump to Line
Something went wrong with that request. Please try again.