简体   繁体   中英

Understanding Ancestor Path Google App Engine

I am looking at some Python code and trying to work what I think are Ancestor Paths.

def parent_key(name = 'default'):
    return ndb.Key('MyEntity', name)

everywhere we have

 MyEntity.get_by_id(someId, parent = parent_key())

I am trying to find the documentation or an explanation as to why this is done, because these entities have no real "parent" in the relational sense.

I have read a bit on GAE documentation but it's still not clear when and when not to do this.

By making the entities have the same parent, you make them part of the same entity group , which can be used to make queries consistent. Normally, the data store doesn't guarantee that an entity can be fetched directly after saving it. It will show up eventually , but that may take a few seconds.

It does however guarantee strong consistency when you do an ancestor query , which is why most of the introductory sample code in the documentation creates all entities with the same parent. This makes it easier to fetch data immediately after saving it, but it does limit the changes to this entity group to about one write per second.

The chapter Structuring Data for Strong Consistency in the documentation has some more details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM