What is the easiest way to delete all my blobstore data?

What is your best way to remove all blob from blobstore? I am using Python.

I have quite a few drops and I would like to remove them. I am currently doing the following:

class deleteBlobs(webapp.RequestHandler): def get(self): all = blobstore.BlobInfo.all(); more = (all.count()>0) blobstore.delete(all); if more: taskqueue.add(url='/deleteBlobs',method='GET'); 

Which seems to use tons of processor and (as far as I can tell) nothing useful.

+4
source share
2 answers

You pass the request object to the delete method, which will iterate over it in batches, and then send one huge delete. This is inefficient because it requires several samples and will not work if you have more results than you can get in available time or with available memory. The task will either be completed once, or will not require a chain at all, or, most likely, will fail again, since it cannot immediately extract each block.

In addition, the call to count only executes the query to determine the count, which is a waste of time, since you will still try to get the results.

Instead, you should get results in batches with fetch and delete each batch. Use the cursors to set the next batch and avoid having to repeat the query on all the β€œgravestone” records before finding the first one alive, and ideally delete several batches per task, using a timer to determine when you should stop and chain the next task.

+4
source

I use this approach:

 import datetime import logging import re import urllib from google.appengine.ext import blobstore from google.appengine.ext import db from google.appengine.ext import webapp from google.appengine.ext.webapp import blobstore_handlers from google.appengine.ext.webapp import util from google.appengine.ext.webapp import template from google.appengine.api import taskqueue from google.appengine.api import users class IndexHandler(webapp.RequestHandler): def get(self): self.response.headers['Content-Type'] = 'text/plain' self.response.out.write('Hello. Blobstore is being purged.\n\n') try: query = blobstore.BlobInfo.all() index = 0 to_delete = [] blobs = query.fetch(400) if len(blobs) > 0: for blob in blobs: blob.delete() index += 1 hour = datetime.datetime.now().time().hour minute = datetime.datetime.now().time().minute second = datetime.datetime.now().time().second self.response.out.write(str(index) + ' items deleted at ' + str(hour) + ':' + str(minute) + ':' + str(second)) if index == 400: self.redirect("/purge") except Exception, e: self.response.out.write('Error is: ' + repr(e) + '\n') pass APP = webapp.WSGIApplication( [ ('/purge', IndexHandler), ], debug=True) def main(): util.run_wsgi_app(APP) if __name__ == '__main__': main() 

My experience is that more than 400 blocks will work, so I can reload them every 400. I tried blobstore.delete(query.fetch(400)) , but I think there is an error right now. Nothing happened and nothing was deleted.

+7
source

All Articles