On Tue, Nov 3, 2009 at 3:41 PM, James Bennett <ubernost...@gmail.com> wrote: > > On Tue, Nov 3, 2009 at 1:17 AM, Low Kian Seong <django....@gmail.com> wrote: >> There is a query page where the start_date and end_date is being sent. >> Then the do_defender_advanced will process it and generate an Excel >> using the template. > > For each object you are displaying the values of four foreign keys. > Each time you access one of those foreign keys, you're doing another > database query; with 3,000 objects and four foreign keys per object, > you'll be doing 12,000 database queries, which is almost certainly why > it's slow.
Okay upon further digging, I commented out the four foreign key lookups in my code, but the timing did not improve. I did this by commenting out the parts. 'record.hd_manager_id.name' but it still takes 50 seconds. > > I suggest you read up on the select_related() method, which can > condense those 12,000 database queries into only one database query. > > > -- > "Bureaucrat Conrad, you are technically correct -- the best kind of correct." > > > > -- Low Kian Seong blog: http://lowkster.blogspot.com --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---