Before you change the code look at it with Appstat.
Then change it too
------------------------------------
outputData['items'] = {}
labelsData = Label.all().fetch(1000)
labelItems = db.get( [Label.item.get_value_for_datastore(label) for
label in labelsData ] )
for label,labelItem in zip(labelsData,labelItems):
name = labelItem.name
try:
outputData['items'][name]['labels'].append(label.text)
except KeyError:
outputData['items'][name] = { 'item' : name, 'labels' : [label.text] }
---------------------------------------
and run Appstat again.
You can use a defaultdict for outputData['items']. it will handle the
try-except. Construct a function that creates the default value.
try-except IS faster then the if-construct. You always do the "if",
you only do the except once for each name. Creating the try-except is
faster then the "if".
And have a look at
http://blog.notdot.net/2010/01/ReferenceProperty-prefetching-in-App-Engine
It handles the case where you might retrieve an Item object multiple times.
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en.