from google.appengine.ext import ndb
import inspect
import models
for kind, model in inspect.getmembers(models):
if not isinstance(model, ndb.model.MetaModel):
continue
cursor = None
while True:
keys, next_cursor, more = \
model.query().fetch_page(500, keys_only=True, start_cursor=cursor)
if keys:
ndb.delete_multi_async(keys)
if more and next_cursor:
cursor = next_cursor
else:
break
假设:
ndb
库models.py
文件然后你可以尝试这样的方法,连接到应用程序的处理程序中:
如果您有很多实体,那么上面的内容可能会在一段时间后用
DeadlineExceededError
终止(在它应该删除一堆实体之后)。要么你重复这个要求直到他们都走了。在或者甚至可以尝试将工作分散到延迟的任务上,在时间上错开以避免有太多可能导致实例爆炸的同时请求。像这样:
^{pr2}$相关问题 更多 >
编程相关推荐