GAE数据存储列表属性序列化 [英] GAE datastore list property serialization

查看:118
本文介绍了GAE数据存储列表属性序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Google I / O 2009观看了这部影片: http:// www。 youtube.com/watch?v=AgaL6NGpkB8 Brett展示微博示例。他描述了两个数据存储模式:

first 一:

class Message .Model):
     sender = db.StringProperty()

     body = db.TextProperty

     receivers = db.StringListProperty()



第二个:<

class Message(db.Model):

     author = db.StringProperty()

     message = db.TextProperty()


class MessageIndex(db.Model) />
     receivers = db.StringListProperty()



他说,每次我们通过接收者查询消息时,示例数据存储都必须序列化/反序列化接收者属性,而第二个例子中没有。我不明白为什么数据存储在这个例子中表现不同,在这两种情况下,接收者只是StringListProperty。你可以解释一下吗?在解释方面,他假设你在查询时想要检索邮件的内容 - '发件人'和'身体'。在App Engine中,实体被整体反序列化 - 你不能只加载某些字段 - 所以当你在第一个例子中进行查询时,它必须加载整个接收者列表。



在第二个示例中,您可以通过MessageIndex执行仅键查询,然后获取并加载相应的消息实体。因为您永远不会将任何MessageIndex属性加载到内存中,所以您不需要反序列化与它们关联的大型且昂贵的listproperty。


I've watched this video from Google I/O 2009: http://www.youtube.com/watch?v=AgaL6NGpkB8 where Brett shows microblogging example. He describes two datastore schemas:

first one:
class Message(db.Model):
    sender = db.StringProperty()
    body = db.TextProperty()
    receivers = db.StringListProperty()

and second one:
class Message(db.Model):
    author = db.StringProperty()
    message = db.TextProperty()

class MessageIndex(db.Model)
    receivers = db.StringListProperty()

And he says that in first example datastore has to serialize/deserialize receivers property every time we query messages by receiver, and in second exaple hasn't. I can't understand why datastore behaves differently in this examples, in both cases receivers is just StringListProperty. Can u explain that?

解决方案

In his talk, he's assuming that when you query, you want to retrieve the contents of the message - 'sender' and 'body'. In App Engine, entities are deserialized as a whole - you can't just load certain fields - so when you do a query in the first example, it has to load the entire list of receivers.

In the second example, you can do a keys-only query over MessageIndex, then fetch and load the corresponding Message entities. Because you never load any MessageIndex properties into memory, you don't need to deserialize the large and expensive listproperty associated with them.

这篇关于GAE数据存储列表属性序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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