Fewer queries on stats of an account balance.
- Remove labels, should be replaced to an anchor to the relative operation in history. - Add select_related as necessary.
This commit is contained in:
parent
b5cc26bb1b
commit
e97e0081d7
1 changed files with 7 additions and 9 deletions
|
@ -2219,10 +2219,13 @@ class AccountStatBalance(PkUrlMixin, JSONDetailView):
|
||||||
# prepare querysets
|
# prepare querysets
|
||||||
# TODO: retirer les opgroup dont tous les op sont annulées
|
# TODO: retirer les opgroup dont tous les op sont annulées
|
||||||
opegroups = OperationGroup.objects.filter(on_acc=account)
|
opegroups = OperationGroup.objects.filter(on_acc=account)
|
||||||
recv_transfers = Transfer.objects.filter(to_acc=account,
|
transfers = (
|
||||||
canceled_at=None)
|
Transfer.objects
|
||||||
sent_transfers = Transfer.objects.filter(from_acc=account,
|
.filter(canceled_at=None)
|
||||||
canceled_at=None)
|
.select_related('group')
|
||||||
|
)
|
||||||
|
recv_transfers = transfers.filter(to_acc=account)
|
||||||
|
sent_transfers = transfers.filter(from_acc=account)
|
||||||
|
|
||||||
# apply filters
|
# apply filters
|
||||||
if begin_date is not None:
|
if begin_date is not None:
|
||||||
|
@ -2250,13 +2253,11 @@ class AccountStatBalance(PkUrlMixin, JSONDetailView):
|
||||||
actions.append({
|
actions.append({
|
||||||
'at': (begin_date or account.created_at).isoformat(),
|
'at': (begin_date or account.created_at).isoformat(),
|
||||||
'amount': 0,
|
'amount': 0,
|
||||||
'label': 'début',
|
|
||||||
'balance': 0,
|
'balance': 0,
|
||||||
})
|
})
|
||||||
actions.append({
|
actions.append({
|
||||||
'at': (end_date or timezone.now()).isoformat(),
|
'at': (end_date or timezone.now()).isoformat(),
|
||||||
'amount': 0,
|
'amount': 0,
|
||||||
'label': 'fin',
|
|
||||||
'balance': 0,
|
'balance': 0,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -2264,21 +2265,18 @@ class AccountStatBalance(PkUrlMixin, JSONDetailView):
|
||||||
{
|
{
|
||||||
'at': ope_grp.at.isoformat(),
|
'at': ope_grp.at.isoformat(),
|
||||||
'amount': ope_grp.amount,
|
'amount': ope_grp.amount,
|
||||||
'label': str(ope_grp),
|
|
||||||
'balance': 0,
|
'balance': 0,
|
||||||
} for ope_grp in opegroups
|
} for ope_grp in opegroups
|
||||||
] + [
|
] + [
|
||||||
{
|
{
|
||||||
'at': tr.group.at.isoformat(),
|
'at': tr.group.at.isoformat(),
|
||||||
'amount': tr.amount,
|
'amount': tr.amount,
|
||||||
'label': str(tr),
|
|
||||||
'balance': 0,
|
'balance': 0,
|
||||||
} for tr in recv_transfers
|
} for tr in recv_transfers
|
||||||
] + [
|
] + [
|
||||||
{
|
{
|
||||||
'at': tr.group.at.isoformat(),
|
'at': tr.group.at.isoformat(),
|
||||||
'amount': -tr.amount,
|
'amount': -tr.amount,
|
||||||
'label': str(tr),
|
|
||||||
'balance': 0,
|
'balance': 0,
|
||||||
} for tr in sent_transfers
|
} for tr in sent_transfers
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in a new issue