Skip to content

Commit

Permalink
Transaction download: Eager load joined tables
Browse files Browse the repository at this point in the history
Performance boost to /api/1/access/transaction.csv

#346
  • Loading branch information
odscjames committed Feb 23, 2022
1 parent a3cba11 commit 863253c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion iati_datastore/iatilib/frontend/dsfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,15 @@ def activities_by_sector(args):


def transactions(args):
return _filter(Transaction.query.join(Activity), args)
# For performance reasons, eager load some extra data we will use later for CSV's.
return _filter(
db.session.query(Transaction).join(Activity).options(
orm.selectinload(Transaction.recipient_country_percentages),
orm.selectinload(Transaction.recipient_region_percentages),
orm.selectinload(Transaction.sector_percentages),
),
args
)


def transactions_by_country(args):
Expand Down

0 comments on commit 863253c

Please sign in to comment.