On Wed, Mar 31, 2010 at 5:22 PM, Federico Capoano
<nemesis.des...@libero.it> wrote:
> Thanks,
>
> how many things i've learnt today, to optimize the number and length
> of query by using:
>
> * select_related
> * only
> * extra
>
> Do you think the performance gain is worth the work?

Yes. Specially in loops where you have:

# in your view
posts = Post.objects.all()[:20]

# in your template
{% for post in posts %}
    {{ post.title }}
    {{ post.category.name }}
    {{ post.owner.username }}
{% endfor %}

post.category and post.owner will hit the database each loop.

> And I've a curiosity more to ask:
> If I use the cache framework, once the results are cached the will the
> database be hit again?

No. But you need to take care of invalidation.

There are few apps that provide drop-out solution for caching at orm level:
 * cache machine - http://jbalogh.me/2010/02/09/cache-machine/
 * cachebot - 
http://blog.davidziegler.net/post/429237463/announcing-django-cachebot
 * johnny cache - http://jmoiron.net/blog/is-johnny-cache-for-you/

Regards,

~Rolando

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to