在App Engine中使用ListProperty或自定义元组属性? [英] Use a ListProperty or custom tuple property in App Engine?

查看:181
本文介绍了在App Engine中使用ListProperty或自定义元组属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google App Engine开发应用程序,并偶然发现了以下情况,可能会将其描述为 MVP -lite。

建立多对多关系时,要使用的标准属性是ListProperty 。很可能,您的列表由另一个模型的外键组成。然而,在大多数实际应用中,当你得到一个键列表 - 对象的名字时 - 通常至少需要一个细节 - 这样你才能构建一个漂亮的超链接到该对象。这需要遍历你的键列表并抓取每个对象以使用其名称属性。



这是最好的方法吗?因为读取便宜,即使我只使用一个对象也可以获得每个对象现在的财产?或者我应该使用特殊的财产,如 tipfy's JsonProperty 保存一个(key,name)元组以避免多余的获取?尽管数据存储读取相对较便宜的数据存储写入,但它们仍然可以将大量时间添加到请求处理程序中。包括对象的名字以及它们的外键听起来就像是非常规化的好用法(例如,使用两个列表属性来模拟一个元组 - 一个包含外键,另一个包含相应的名称)。



如果您决定反对这种非规范化,那么我建议您批量获取外键参考的实体(而不是逐个获取它们),这样至少可以减少往返次数你进入数据存储。


I'm developing an application with Google App Engine and stumbled across the following scenario, which can perhaps be described as "MVP-lite".

When modeling many-to-many relationships, the standard property to use is the ListProperty. Most likely, your list is comprised of the foreign keys of another model.

However, in most practical applications, you'll usually want at least one more detail when you get a list of keys - the object's name - so you can construct a nice hyperlink to that object. This requires looping through your list of keys and grabbing each object to use its "name" property.

Is this the best approach? Because "reads are cheap", is it okay to get each object even if I'm only using one property for now? Or should I use a special property like tipfy's JsonProperty to save a (key, name) "tuple" to avoid the extra gets?

解决方案

Though datastore reads are comparatively cheaper datastore writes, they can still add significant time to request handler. Including the object's names as well as their foreign keys sounds like a good use of denormalization (e.g., use two list properties to simulate a tuple - one contains the foreign keys and the other contains the corresponding name).

If you decide against this denormalization, then I suggest you batch fetch the entities which the foreign keys refer to (rather than getting them one by one) so that you can at least minimize the number of round trips you make to the datastore.

这篇关于在App Engine中使用ListProperty或自定义元组属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆