本文介绍了Google Appengine NDB祖先与关键查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将一个实体的密钥存储为另一个实体的一个属性,以便将它们关联起来。在这个项目中,我们正在进行重构阶段,所以我正在考虑引进祖先。
这两种方法之间是否存在性能差异?如果我们引进祖先,我可能获得哪些优势?

  class Book(ndb.Model):
.. 。

class Article(ndb.Model:
book_key = ndb.KeyProperty(kind = Book,required = True)


book_key = ndb。 Key(Book,12345)

第一个祖先查询方法 p>

  qry = Article.query(ancestor = book_key)

第二种简单的关键查询方式

  qry =文章.query(book_key = book_key)


解决方案

祖先查询将始终保持完全一致,另一方面,通过 book_key 查询不一定是一致的:您可能会发现最近的更改不会显示在该查询中。



另一方面,引入祖先对更新次数施加限制:每秒只能对任何实体gr进行一次更新oup(即祖先及其子女)。



这对你来说是一种权衡,哪一个在你的应用中更重要。 b

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)

1st ancestor query approach

qry = Article.query(ancestor=book_key)

2st simple key query approach

qry = Article.query(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祖先与关键查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 15:36