A query optimization in bda.views.catalogue

We only need to fetch shows identifiers here:

    FOO.filter(BAR__in=shows)

which can be done using the `values_list` method
This commit is contained in:
Martin Pépin 2017-04-05 20:48:18 +01:00
parent ff9cee5ffc
commit 9ec151e040

View file

@ -672,15 +672,16 @@ def catalogue(request, request_type):
return HttpResponseBadRequest(
"Bad format: int expected for `id`"
)
shows = tirage.spectacle_set.values_list("id", flat=True)
categories = list(
CategorieSpectacle.objects
.filter(spectacle__in=tirage.spectacle_set.all())
.filter(spectacle__in=shows)
.distinct()
.values('id', 'name')
)
locations = list(
Salle.objects
.filter(spectacle__in=tirage.spectacle_set.all())
.filter(spectacle__in=shows)
.distinct()
.values('id', 'name')
)