From 6c31f89db468c6a3581a79cbd2b7805e3cb4fb7a Mon Sep 17 00:00:00 2001 From: Alexandre Avenel Date: Sun, 25 Sep 2016 17:02:31 +0200 Subject: [PATCH] Optim balances computation Query only bills associated with project first --- budget/models.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/budget/models.py b/budget/models.py index 852b3e19..9ae77d8a 100644 --- a/budget/models.py +++ b/budget/models.py @@ -35,10 +35,11 @@ class Project(db.Model): for time in (1, 2, 3)) # for each person + bills_in_project = self.get_bills() for person in self.members: # get the list of bills he has to pay - bills = Bill.query.filter(Bill.owers.contains(person)) - for bill in bills.all(): + bills = bills_in_project.filter(Bill.owers.contains(person)).all() + for bill in bills: if person != bill.payer: share = bill.pay_each() * person.weight should_pay[person] += share