django url tag performance

Posted by zxygentoo on Stack Overflow See other posts from Stack Overflow or by zxygentoo
Published on 2010-04-09T17:19:32Z Indexed on 2010/04/09 17:23 UTC
Read the original article Hit count: 240

Filed under:
|
|

I was trying to integrate django-voting into my project following the RedditStyleVoting instruction.

In my urls.py, i did something like this:

    url(r'^sections/(?P<object_id>\d+)/(?P<direction>up|down|clear)vote/?$',
    vote_on_object,
    dict(
        model=Section,
        template_object_name='section',
        template_name='script/section_confirm_vote.html',
        allow_xmlhttprequest=True
        ),
    name="section_vote",

then, in my template:

{% vote_by_user user on section as vote %} {% score_for_object section as score %}

 {% vote_by_user user on section as vote %}

{% score_for_object section as score %}

{{ score.score|default:0 }}

It takes over 1.3s to load the page, but by hard coding it like this:

 {% vote_by_user user on section as vote %}

{% score_for_object section as score %}

{{ score.score|default:0 }}

I got 50ms. Just avoid the url tag resolving stuff I got a 20+ times performance improvement. Is there something I did wrong? If not, then what's the best practice here, should we do things the right way or the fast way?

© Stack Overflow or respective owner

Related posts about django

Related posts about Performance