unepwcmc/SAPI — pull request #391 by agnessa (2014-09-23 11:18:55+00:00)
Title: Fix for cascading trade searches

The issue would occur when searching in the admin interface by taxa with many descendants, e.g. Plants. The csv download would be aborted without a conclusive error message, and the web report would go on forever.

The problem was caused by the 'IN' condition used for matching on taxon_concept_id. That was replaced by a join with taxon concepts and a much simpler condition which makes use of the ancestor ids stored in taxon concepts. The join is embedded in the underlying database view, to simplify queries (especially for purposes of csv generation).

Also, the raw report in its web form had the 1+n queries issue, caused by serializing taxon concept & reported taxon concept. I added a new serializer, which instead of fetching the taxon concept records populates the serialized object with data already fetched from the view.

I also removed the database view, which was previosly used to generate raw csv outputs; the query was moved to the amazing `Trade::ShipmentReportQueries` module, for lack of better idea and for consistency with comptab / net gross outputs.

Needs:
`rake db:migrate`
`rake downloads:cache:clear`

Affects:
all shipment search reports, both web based and csv based, both admin and public.