I am using Django to display a series of test results. I created a view to show the most recent instance of each test result.
1: results = resultTable.objects.order_by('id')
2: latestResults = {}
3: for res in results: latestResults[res.testcase.name] = res.id
4: latestResultQuerySet = resultTable.objects.filter(id__in=latestResults.values())
5: del latestResults
6: return HttpResponse()
Line 1 creates a QuerySet of about 20,000 entries in about 1 second.
Line 3 calculates the id of the latest results of each testcase in about 12 seconds.
Line 4 create a new QuerySet of about 800 entries using those ids in about 1 second.
Line 5 deletes the dictionary in essentially no time.
From this I would think the (blank) page would load in about 15 seconds. In practice it take about 3 minutes to load.
Removing line 3 allows the page to load instantly.
Any ideas what is causes the extra 2+ minutes of delay? Since I am not passing anything to the HttpResponse I assumed it had something to do with the garbage collection of the dictionary, thus line 5 was born.