简体   繁体   English

在谷歌应用引擎数据存储上做 ONE:ONE 关系的最有效方法是什么

[英]What is the most efficient way to do a ONE:ONE relation on google app engine datastore

Even with all I do know about the AppEngine datastore, I don't know the answer to this.即使我对 AppEngine 数据存储区了解的一切,我也不知道答案。 I'm trying to avoid having to write and run all the code it would take to figure it out, hoping someone already knows the answer.我试图避免编写和运行所有代码来解决这个问题,希望有人已经知道答案。

I have code like:我有如下代码:

class AddlInfo(db.Model)
     user = db.ReferenceProperty(User)
     otherstuff = db.ListProperty(db.Key, indexed=False)

And create the record with:并使用以下命令创建记录:

info = AddlInfo(user=user)
info.put()

To get this object I can do something like:为了得到这个 object 我可以这样做:

# This seems excessively wordy (even though that doesn't directly translate into slower)
info = AddlInfo.all().filter('user =', user).fetch(1)

or I could do something like:或者我可以做类似的事情:

class AddlInfo(db.Model)
     # str(user.key()) is the key to this record
     otherstuff = db.ListProperty(db.Key, indexed=False)

Creation looks like:创作看起来像:

info = AddlInfo(key_name=str(user.key()))
info.put()

And then get the info with:然后通过以下方式获取信息:

info = AddlInfo.get(str(user.key()))

I don't need the reference_property in the AddlInfo, (I got there using the user object in the first place).我不需要 AddlInfo 中的 reference_property(我首先使用用户 object 到达那里)。 Which is faster/less resource intensive?哪个更快/更少资源密集?

================== ===================

Part of why I was doing it this way is that otherstuff could be a list of 100+ keys and I only need them sometimes (probably less than 50% of the time) I was trying to make it more efficient by not having to load those 100+ keys on every request.....我这样做的部分原因是其他东西可能是 100 多个键的列表,而我有时只需要它们(可能不到 50% 的时间)我试图通过不必加载它们来提高效率每个请求都有 100 多个键.....

Between those 2 options, the second is marginally cheaper, because you're determining the key by inference rather than looking it up in a remote index.在这两个选项之间,第二个稍微便宜一些,因为您是通过推理来确定密钥,而不是在远程索引中查找它。

As Wooble said, it's cheaper still to just keep everything on one entity.正如 Wooble 所说,将所有东西都放在一个实体上仍然更便宜。 Consider an Expando if you just need a way to store a bunch of optional, ad-hoc properties.如果您只需要一种方法来存储一堆可选的临时属性,请考虑使用Expando

The second approach is the better one, with one modification: There's no need to use the whole key of the user as the key name of this entity - just use the same key name as the User record.第二种方法更好,有一个修改:不需要使用用户的整个键作为该实体的键名 - 只需使用与用户记录相同的键名即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 数据存储区一对多Google App Engine - Datastore One-to-Many Google App Engine 在Google Appengine中使用数据存储区的最有效方法是什么? - What is the most efficient way to use datastore in google appengine? google app engine将大数据放入数据存储区的有效方法 - google app engine Efficient way to put large data in datastore 如何在Python Google Appengine数据存储区中实现一对一关系? - How to do one to one relation in python google appengine datastore? 用一对一关系连接模型的有效方法是什么? - What is the efficient way to connect models with a one to one relation? MapReduce在Google App Engine中的多种数据存储类型上 - MapReduce on more than one datastore kind in Google App Engine 将数据库从一种格式更改为另一种格式。 什么是最有效的方法? - Change database from one format to another. What is most efficient way to do this? 使用ndb更新谷歌应用引擎数据存储区上的多个实例的最便捷方式 - Most convenient way to update multiple instances on google app engine datastore with ndb 在另一个数组中找到一个 numpy 数组的行列的最有效方法是什么? - What is the most efficient way of finding the ranks of one numpy array in another? 在python中将两个数字连接到一个数字的最有效方法是什么? - what is the most efficient way of concat two numbers to one number in python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM