More query optimisation
This commit is contained in:
parent
62858b0f6e
commit
36d658e57f
1 changed files with 11 additions and 4 deletions
|
@ -481,11 +481,18 @@ def attendee(request, form, user_id=None):
|
||||||
def attendee_list(request):
|
def attendee_list(request):
|
||||||
''' Returns a list of all attendees. '''
|
''' Returns a list of all attendees. '''
|
||||||
|
|
||||||
attendees = people.Attendee.objects.all().select_related(
|
attendees = people.Attendee.objects.select_related(
|
||||||
"attendeeprofilebase",
|
"attendeeprofilebase",
|
||||||
"user",
|
"user",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
profiles = AttendeeProfile.objects.filter(
|
||||||
|
attendee__in=attendees
|
||||||
|
).select_related(
|
||||||
|
"attendee", "attendee__user",
|
||||||
|
)
|
||||||
|
profiles_by_attendee = dict((i.attendee, i) for i in profiles)
|
||||||
|
|
||||||
attendees = attendees.annotate(
|
attendees = attendees.annotate(
|
||||||
has_registered=Count(
|
has_registered=Count(
|
||||||
Q(user__invoice__status=commerce.Invoice.STATUS_PAID)
|
Q(user__invoice__status=commerce.Invoice.STATUS_PAID)
|
||||||
|
@ -501,8 +508,8 @@ def attendee_list(request):
|
||||||
for a in attendees:
|
for a in attendees:
|
||||||
data.append([
|
data.append([
|
||||||
a.user.id,
|
a.user.id,
|
||||||
a.attendeeprofilebase.attendee_name()
|
(profiles_by_attendee[a].attendee_name()
|
||||||
if hasattr(a, "attendeeprofilebase") else "",
|
if a in profiles_by_attendee else ""),
|
||||||
a.user.email,
|
a.user.email,
|
||||||
a.has_registered > 0,
|
a.has_registered > 0,
|
||||||
])
|
])
|
||||||
|
|
Loading…
Reference in a new issue