开发者

Clarification: can I put all of a user's data in a single entity group by making up an ancestor key?

开发者 https://www.devze.com 2023-01-19 18:46 出处:网络
I want to do several operations on a user\'s data in a single transaction, but won\'t need to update multiple users\' data in a single transaction.I see from http://code.google.com/appengine/docs/pyth

I want to do several operations on a user's data in a single transaction, but won't need to update multiple users' data in a single transaction. I see from http://code.google.com/appengine/docs/python/datastore/keysandentitygroups.html#Entity_Groups_Ancestors_and_Paths that "A good rule of thumb for entity groups is that [entity groups]开发者_Go百科 should be about the size of a single user's worth of data or smaller," so I think the correct choice is to use a single parent key when building the keys for the other entities related to a user.

  1. Does this seem like a good idea?
  2. Is it easy to code? Something like KeyBuilder.setParent(theKeyOfMyUserEntity)?


1) It is hard to comment without some addition details about the data. There are several things you should be aware of with entity groups; the biggest is that the group will be stored together. That means if you are trying to do many (separate) updates you could face contention, limiting your app's performance.

2) yes it is easy to code. The syntax is pretty close to what you posted.

There are other options for transactions. Check out Nick Johnson's article on distributed transactions. If you are wanting transactions for aggregates you should also check out Brett Slatkin's IO talk on high-throughput data pipelines.


  1. Yes, it seems reasonable to store some user data as child entities of a User entity.

  2. Why do you need to manually create keys ? The db.Model() constructor already has a convenient "parent" argument which will automatically put both the parent entity and the child entity in the same entity group.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号