Created
October 31, 2015 18:29
-
-
Save spencerroan/af50956a5f527984872b 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
| 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 | |
You might want find_each so you don't load them all in memory. But other than that looks good.
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

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.