Created
April 17, 2009 11:37
-
-
Save marksim/96985 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Method to slowly delete items from a db giving sleep time between deletions to prevent longer term locking | |
def slow_delete(num1, num2=nil, options={}) | |
step = options[:step] || 5000 | |
sleeptime = options[:sleep] || 2 | |
klazz = options[:class] || Log | |
if num2.nil? | |
num2 = num1 | |
num1 = 0 | |
end | |
m = num1+step | |
t = 0 | |
while m < num2 | |
t += klazz.delete_all("id < #{m} and id >= #{m-step}") | |
m += step | |
print "." | |
sleep sleeptime | |
end | |
t += klazz.delete_all("id < #{num2} and id >= #{m}") | |
t | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment