Fewer db accesses on transfers list view.

- Add select_related for `from_acc`, `to_acc` and `group.valid_by`.
- 2 requests instead of (3 * #transfers)
This commit is contained in:
Aurélien Delobelle 2017-04-06 18:42:00 +02:00
parent 709d421b2c
commit f8b71b604c

View file

@ -1477,19 +1477,32 @@ class SettingsUpdate(SuccessMessageMixin, UpdateView):
Settings.empty_cache()
return super(SettingsUpdate, self).form_valid(form)
# -----
# Transfer views
# -----
@teamkfet_required
def transfers(request):
transfergroups = (TransferGroup.objects
.prefetch_related('transfers')
.order_by('-at'))
transfers_pre = Prefetch(
'transfers',
queryset=(
Transfer.objects
.select_related('from_acc', 'to_acc')
),
)
transfergroups = (
TransferGroup.objects
.select_related('valid_by')
.prefetch_related(transfers_pre)
.order_by('-at')
)
return render(request, 'kfet/transfers.html', {
'transfergroups': transfergroups,
})
@teamkfet_required
def transfers_create(request):
transfer_formset = TransferFormSet(queryset=Transfer.objects.none())