Open odscjames opened 2 years ago
First pull request done. However there is more we might be able to do here, there are still secondary SQLs happening.
In particular, activity is joined to the main transaction SQL just for sorting then not selected, so secondary SQLs are made to load the activity later! Adding orm.joinedload(Transaction.activity),
would probably be good here but then the sort by starts to complain, so that needs more attention. Note that many transactions may have one activity here, so it's less certain there will be good gains here but it seems worth trying.
https://github.com/codeforIATI/iati-datastore/pull/350 speeds up by_sector & by_country.
When doing the by_country one, there are still a lot of SQL fetches for individual organisations. Maybe there is another quick speed up possible here.
Describe the bug
Transactions CSV (and Excel) is slow
Issue
For every hit on the transaction, we get lots of individual DB queries:
Those 3 queries are repeated heavily.
These python functions get the extra data:
There are also some queries to get extra info on
organisation
,participation
andactivity
tables that did not repeat in my test data set (I think because SQLLachemy caches?), but should repeat on larger data sets.Possible solutions
These actual DB queries are really fast as you can see above, but they do add up and there are a lot of them.
If we are lucky some joining on the original query to avoid later queries will really boost this.