Optim balances computation

Query only bills associated with project first
This commit is contained in:
Alexandre Avenel 2016-09-25 17:02:31 +02:00
parent fb69e8aa89
commit 6c31f89db4

View file

@ -35,10 +35,11 @@ class Project(db.Model):
for time in (1, 2, 3)) for time in (1, 2, 3))
# for each person # for each person
bills_in_project = self.get_bills()
for person in self.members: for person in self.members:
# get the list of bills he has to pay # get the list of bills he has to pay
bills = Bill.query.filter(Bill.owers.contains(person)) bills = bills_in_project.filter(Bill.owers.contains(person)).all()
for bill in bills.all(): for bill in bills:
if person != bill.payer: if person != bill.payer:
share = bill.pay_each() * person.weight share = bill.pay_each() * person.weight
should_pay[person] += share should_pay[person] += share