From 59b6b6ed780d6f2720665ddf5e290b01cafd3e7b Mon Sep 17 00:00:00 2001 From: James Date: Thu, 7 Apr 2022 10:25:57 +0100 Subject: [PATCH] Transaction by sector download: Eager load joined tables Performance boost to /api/1/access/transaction/by_sector.csv https://github.com/codeforIATI/iati-datastore/issues/346 Similiar to 863253cb3c83aed862908d77c310883d13131e0c --- iati_datastore/iatilib/frontend/dsfilter.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/iati_datastore/iatilib/frontend/dsfilter.py b/iati_datastore/iatilib/frontend/dsfilter.py index bced2093..3ddf200b 100644 --- a/iati_datastore/iatilib/frontend/dsfilter.py +++ b/iati_datastore/iatilib/frontend/dsfilter.py @@ -361,7 +361,12 @@ def transactions_by_sector(args): return _filter( db.session.query(Transaction, SectorPercentage) .join(Activity, Activity.iati_identifier==Transaction.activity_id) - .join(SectorPercentage), + .join(SectorPercentage) + .options( + orm.selectinload(Transaction.recipient_country_percentages), + orm.selectinload(Transaction.recipient_region_percentages), + orm.selectinload(Transaction.sector_percentages), + ), args )