Thanks!

I'm trying to follow the logic of your suggestion all the way to rendering 
it, tell me if you have a better idea:
once I hold the list of articles I want to show, I run over the list and 
get all the comment ids, I issue a large query with the ids of all comments 
for all articles together, pass it to the view as a large dictionary that 
has a key of article id and value list of comments and use it like that?


On Tuesday, March 27, 2012 6:11:46 AM UTC-4, Wikus van de Merwe wrote:
>
> When working with GAE datastore you want to execute minimum number of 
> queries necessary to avoid delays and
> limit the use of DB API calls. Fetching comments one by one is not the 
> best option then (even if done with ajax).
>
> Probably the most efficient way would be to store the list of comment ids 
> as an attribute of each article entity. Then
> you could get all comment ids with a single query. Having the ids you 
> could build a list of GAE keys, and fetch all
> needed comment entities at once. We discussed that recently here:
> https://groups.google.com/d/topic/web2py/7dvo_jqIR38/discussion
>
> I'm also guessing that this might be quite common GAE use case and you 
> might find a better solution already optimised
> for this on GAE forum. The other option is to show comments only on the 
> article individual page (not on the list of articles).
>
> If you use the wrapper for caching, then you could memorize the entire 
> response, so this is very efficient as the views
> are not rendered but read straight from cache. If you need some extra 
> parametrisation inside the controller you could
> either move some of the code to a separate function which output is cached 
> or simply cache only the queries:
> http://web2py.com/books/default/chapter/29/6#Caching-selects
>
>

Reply via email to