aboutsummaryrefslogtreecommitdiff
path: root/budget
diff options
context:
space:
mode:
authorAlexis Metaireau <alexis@notmyidea.org>2017-01-16 21:15:43 +0100
committerGitHub <noreply@github.com>2017-01-16 21:15:43 +0100
commit8615fde00ad4c402a8cad3bd23c7a0e4e3788d32 (patch)
tree7b2f7a58a5ae744555de148d362da241533d338b /budget
parentdc75a72dd0caeafce20b09d3ad538bdcbabf4408 (diff)
parent8e5ac8ae98824b8b359cc0f020b10acb29985dab (diff)
downloadihatemoney-mirror-8615fde00ad4c402a8cad3bd23c7a0e4e3788d32.zip
ihatemoney-mirror-8615fde00ad4c402a8cad3bd23c7a0e4e3788d32.tar.gz
ihatemoney-mirror-8615fde00ad4c402a8cad3bd23c7a0e4e3788d32.tar.bz2
Merge pull request #161 from zorun/optimise_sql
Optimise sql queries
Diffstat (limited to 'budget')
-rw-r--r--budget/models.py2
-rw-r--r--budget/web.py4
2 files changed, 4 insertions, 2 deletions
diff --git a/budget/models.py b/budget/models.py
index 0670d6e..3aac120 100644
--- a/budget/models.py
+++ b/budget/models.py
@@ -37,7 +37,7 @@ class Project(db.Model):
# for each person
for person in self.members:
# get the list of bills he has to pay
- bills = Bill.query.filter(Bill.owers.contains(person))
+ bills = Bill.query.options(orm.subqueryload(Bill.owers)).filter(Bill.owers.contains(person))
for bill in bills.all():
if person != bill.payer:
share = bill.pay_each() * person.weight
diff --git a/budget/web.py b/budget/web.py
index 63fbe4d..87aef26 100644
--- a/budget/web.py
+++ b/budget/web.py
@@ -15,6 +15,7 @@ from flask.ext.mail import Mail, Message
from flask.ext.babel import get_locale, gettext as _
from smtplib import SMTPRecipientsRefused
import werkzeug
+from sqlalchemy import orm
# local modules
from models import db, Project, Person, Bill
@@ -277,7 +278,8 @@ def list_bills():
# set the last selected payer as default choice if exists
if 'last_selected_payer' in session:
bill_form.payer.data = session['last_selected_payer']
- bills = g.project.get_bills()
+ # Preload the "owers" relationship for all bills
+ bills = g.project.get_bills().options(orm.subqueryload(Bill.owers))
return render_template("list_bills.html",
bills=bills, member_form=MemberForm(g.project),