Real nice, thanks! Defiantly a great improvement.
2 questions.
1. Could you elaborate what these lines does?
labelItems = db.get([Label.item.get_value_for_datastore(label) for label in
labelsData ])
for label,labelItem in zip(labelsData,labelItems):
Don't really understand them.
2. The page renders really fast, but usage is about 2345cpu_ms 2112api_cpu_ms
when I knock it up to 30 items and 120 labels. Is any thing else one could do?
I could use memcache but this will be used at a page where it's displayed only
after an update.
..fredrik
On 8 jun 2010, at 11.38, djidjadji wrote:
> 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.
>
--
Fredrik Bonander
[email protected]
+46 70 943 5441
- the infinite power of the creative mind -
--
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.