2011/12/5 kenneth gonsalves <law...@thenilgiris.com>

>  The code looks simple to me, but to analyse 10,000 rounds of golf
> (1,80,000 hole scores) my 2 GB laptop takes 20 minutes. Would this be
> considered normal - or slow? If slow, ideas on how to speed it up would be
> appreciated.
>
>
One thing you should look into is QuerySet.select_related():
https://docs.djangoproject.com/en/dev/ref/models/querysets/#select-related

Without it, every time you run scr.hole on a new scr, Django will run a new
query, fetching that 'hole' object. If you have 10 000 scores, that means
10 000 queries, which is an insane number for queries like this. If you use
select_related, Django will fetch the corrosponding hole for you, in the
same query... meaning 1 query, instead of 10 000 :)

In other words, change this:


    scrs = Score.objects.all()    pscrs =
Pscore.objects.filter(hole__tee__course = club)


To this:


    scrs = Score.objects.all().select_related('hole')    pscrs =
Pscore.objects.filter(hole__tee__course = club).select_related('hole')


That seems to be the biggest problem you have. Some other comments:

- Holy mother of god, that's a huge view file! I would advice to slice
it into logically separated files, and put this in a directory called
"views", everything doesn't have to be in views.py!

- Put your forms in another file, like forms.py

- If you're just checking if someone is logged in with
@user_passes_test, why not just use @login_required?

- Check out render:
https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#render


Best regards,

Håkon Erichsen

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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