且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Google App Engine ndb.delete_multi()的效率如何?

更新时间:2023-11-29 16:18:16

您的代码示例效率极低.如果要删除大量实体,则需要对以下实体进行批处理,但是,应使用keys_only查询检索数据,然后删除:

Your code example is extremely inefficient. If you are deleting large numbers of entities than you will need to batch the below but, you should be retrieving data with a keys_only query and then deleting:

from google.appengine.ext import ndb

ndb.delete_multi(
    MyModel.query().fetch(keys_only=True)
)

关于写操作的数量(请参阅Andrei的答案),请仅确保模型上需要索引的字段已启用索引".

In regards to the number of write operations (see Andrei's answer), ensure only the fields on your model that are required to be indexed "have an index enabled".