Is it possible to find and delete orphaned blobs in the app engine blobstore?

余生长醉 提交于 2019-12-29 06:26:08

问题


I'm using the python api and have created a few orphaned blobs during testing.

Because of a bug in the dashboard, I can't currently delete these, and in any case going forward I would like to be able to do this programmatically since it will be unfeasible to do it manually once the number of entities goes up.


回答1:


If your BlobReferenceProperty field is indexed, then yes, it's quite possible.

The BlobInfo class provides the same set of fields as a regular model, so you can do it something like this:

blobs = BlobInfo.all().fetch(500)
for blob in blobs:
  if not MyModel.all().filter("blob_ref =", blob.key()).count(1):
    blob.delete()

If you have more than a few blobs, you probably want to reimplement this using the recently reduced mapreduce API.




回答2:


Slight improvement: using run instead of fetch will return an iterable instead of a list, so you don't need to limit the number of entries in the query:

blobs = BlobInfo.all().run()

instead of

blobs = BlobInfo.all().fetch(500)


来源:https://stackoverflow.com/questions/2935980/is-it-possible-to-find-and-delete-orphaned-blobs-in-the-app-engine-blobstore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!