On Mon, 2011-12-05 at 11:18 +0100, Håkon Erichsen wrote: > 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')
I first did select_related() and the laptop nearly caught fire! timed out after an hour or so. I then did select_related(depth=1) and it took less than a minute. > > > > > > 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! > there is a lot of duplicated code - a huge clean up is needed, but every time I sit to do it, a new feature is needed, so it does not get done! > - Put your forms in another file, like forms.py that is on the todo list. > > - If you're just checking if someone is logged in with @user_passes_test, why > not just use @login_required? this is legacy code - at the time it was written, login_required did not do what I wanted, I need to review that. > > - Check out render: > https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#render > > will do - thanks to all for taking the trouble of reading the code and making suggestions. -- regards Kenneth Gonsalves -- 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.