Skip to content

Instantly share code, notes, and snippets.

@spencerroan
Created October 31, 2015 18:29
Show Gist options
  • Save spencerroan/af50956a5f527984872b to your computer and use it in GitHub Desktop.
Save spencerroan/af50956a5f527984872b to your computer and use it in GitHub Desktop.
def remove_membership(membership)
ii = Stripe::InvoiceItem.retrieve(membership.stripe_invoice_item)
ii.delete
rescue
#nothing
end
def kill_stripe(n=30)
query = Membership.where(Membership.arel_table[:updated_at].gt 33.days.ago).where.not(stripe_invoice_item: nil)
count = query.count
size = [n,count].min
pb = ProgressBar.new("die", size)
query.limit(size).each do |membership|
remove_membership(membership)
pb.inc
end
pb.finish
end
@spencerroan
Copy link
Author

There are 1452 in prod that have an id and have been updated recently

It took 2 minutes in stage to lookup 500 there were none to delete in stage.

so it could take 12 minutes to run through deleting them.

@spencerroan
Copy link
Author

screen shot 2015-10-31 at 12 32 37 pm

@ketiko
Copy link

ketiko commented Oct 31, 2015

You might want find_each so you don't load them all in memory. But other than that looks good.

@spencerroan
Copy link
Author

find each did funny stuff to the progress bar. find each finds in batches of 1k, so i'm not worried about an extra 500. I'm gonna give it a shot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment