don't generate new case list
use generator for case_xml_elements
only fetch previous transaction if needed
select stock transactions in bulk
remove unnecessary count
more efficient fetching of stock transactions
Merge pull request #4779 from dimagi/restore

restore performance improvements