问题描述
我将一个实体的键存储为另一个实体的属性,以便将它们关联起来.在项目的这一点上,我们处于重构阶段,所以我在考虑引入祖先.这两种方法之间是否存在性能差异?如果我们介绍祖先,我可能会获得什么优势?
I am storing a key of an entity as a property of another in order to relate them. We are in a refactor stage at this point in the project so I was thinking about introducing ancestors.Is there a performance difference between the two approaches? Any given advantages that I might gain if we introduce ancestors?
class Book(ndb.Model):
...
class Article(ndb.Model):
book_key = ndb.KeyProperty(kind=Book, required=True)
book_key = ndb.Key("Book", 12345)
第一个祖先查询方法
qry = Article.query(ancestor=book_key)
第二个简单的键查询方法
qry = Article.query(book_key=book_key)
推荐答案
祖先查询将始终完全一致.另一方面,通过 book_key
查询不一定一致:您可能会发现该查询中不会显示最近的更改.
The ancestor query will always be fully consistent. Querying by book_key
, on the other hand, will not necessarily be consistent: you may find that recent changes will not be shown in that query.
另一方面,引入祖先对更新次数施加了限制:您每秒只能对任何实体组(即祖先及其子代)进行一次更新.
On the other hand, introducing an ancestor imposes a limit on the number of updates: you can only do one update per second to any entity group (ie the ancestor and its children).
对于您的应用中哪一个更重要,这对您来说是一种权衡.
It's a trade-off for you as to which one is more important in your app.
这篇关于Google Appengine NDB 祖先 vs 键查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!