Consider these two cases in app engine datastore design:
I can see these advantages in case 2:
Are the above points correct? When and why should case 1 be used over case 2?
答案 0 :(得分:2)
XG事务只能跨越25个不同的实体组,因此对单个批次中可以进行的多个更改的数量进行限制。另外,使用祖先允许您对祖先组内的数据构建查询。
考虑一个简单的微博网站示例,用户可以在该网站上发帖并查看其他用户的帖子。您的主页显示所有用户的最新帖子,因此执行最终一致的查询以获取此数据是可以的(我们可以容忍这里的一些陈旧性)。但是,当用户发帖时,他们应该始终看到该帖子显示在他们的Feed中。
如果您将每个帖子存储在自己的EG中,那么您对用户帖子的查询可能如下所示:SELECT * FROM Post WHERE author = $current_user
。但是,这最终是一致的。因此,用户可以发布帖子,然后不会将其显示在其Feed中。相反,我们可以利用EG并使每个Post
成为创建它的User
的孩子。然后,我们可以使用SELECT * FROM Post WHERE __key__ HAS ANCESTOR KEY('User', $current_user)
查询单个用户的帖子。
在这种情况下,用户将被限制为每秒创建1个帖子,但是这与自然边界很好地对齐 - 此时用户被限制为键入a所需的时间交。