speed up dashboard queries by using select_related (fixes #233)

This commit is contained in:
Ross Poulton 2014-07-23 09:37:21 +10:00
parent 1524cb4ca1
commit b1b1f93e1e

View File

@ -62,18 +62,18 @@ def dashboard(request):
""" """
# open & reopened tickets, assigned to current user # open & reopened tickets, assigned to current user
tickets = Ticket.objects.filter( tickets = Ticket.objects.select_related('queue').filter(
assigned_to=request.user, assigned_to=request.user,
).exclude( ).exclude(
status__in = [Ticket.CLOSED_STATUS, Ticket.RESOLVED_STATUS], status__in = [Ticket.CLOSED_STATUS, Ticket.RESOLVED_STATUS],
) )
# closed & resolved tickets, assigned to current user # closed & resolved tickets, assigned to current user
tickets_closed_resolved = Ticket.objects.filter( tickets_closed_resolved = Ticket.objects.select_related('queue').filter(
assigned_to=request.user, assigned_to=request.user,
status__in = [Ticket.CLOSED_STATUS, Ticket.RESOLVED_STATUS]) status__in = [Ticket.CLOSED_STATUS, Ticket.RESOLVED_STATUS])
unassigned_tickets = Ticket.objects.filter( unassigned_tickets = Ticket.objects.select_related('queue').filter(
assigned_to__isnull=True, assigned_to__isnull=True,
).exclude( ).exclude(
status=Ticket.CLOSED_STATUS, status=Ticket.CLOSED_STATUS,
@ -83,7 +83,7 @@ def dashboard(request):
all_tickets_reported_by_current_user = '' all_tickets_reported_by_current_user = ''
email_current_user = request.user.email email_current_user = request.user.email
if email_current_user: if email_current_user:
all_tickets_reported_by_current_user = Ticket.objects.filter( all_tickets_reported_by_current_user = Ticket.objects.select_related('queue').filter(
submitter_email=email_current_user, submitter_email=email_current_user,
).order_by('status') ).order_by('status')