Can I have the benefit of parent-child relations without the cost of datastore contention?

爷,独闯天下 提交于 2019-12-11 01:27:06

问题


Assumptions: 1) Google AppEngine has the concept of Entity Groups. 2) Entities in an entity group form a tree. However, as far as I understood, every put() to any entity in that tree will lock the whole tree (not just the immediate parent) for a while. 3) Users are allowed to write ca. 5 times per seconds to the tree. 4) There is no way to have a non-locking behaviour (i.e. by making them unindexed properties)

Would it be a smart idea to come up with my own parent-child model that does not use the built-in Key-functions (as those would create entity groups) but instead use some snytax convetions that I made up? This would allow me to retrieve a "child" entity via a query an compute the parent key.


回答1:


The ancestor relationship used by entity groups can be modeled in your own code by using a list of references/keys to parent entities. Root entities will have none, children of roots will have just the root entity in their list, their children will have the root and their immediate parent, and so forth. This is how ancestors are implemented in App Engine for indexing purposes, and it'll permit you to make the same sorts of queries.




回答2:


You can use a reference property:

class Parent(db.Model):
    x = db.IntegerProperty()

class Child(db.Model):
    parent = db.ReferenceProperty(
        reference_class = Parent, 
        collection_name = 'children')
    y = db.IntegerProperty()


来源:https://stackoverflow.com/questions/3704068/can-i-have-the-benefit-of-parent-child-relations-without-the-cost-of-datastore-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!