Hi, 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?
views:
309answers:
1
+1
A:
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.
Nick Johnson
2009-10-29 10:12:18
I understood it already, but thanks anyway :). You are absolutely right.
giolekva
2009-10-29 18:57:00