There's a lot of waiting involved in making chai so I decided to work on porting another report from the old Typica code base into the new one. The old code for this one takes a working but naive approach that involves far too many database queries. I've cut that down to 2 queries with a bit of client side processing combining the results. It's likely possible to cut it back to 1 query with exactly what I need, but I'm not confident that I would understand it later.
There probably is some room to clean up the first of the two queries to make that a bit more clear. That might be a useful step toward getting to an understandable 1 query solution and it would give the planner less work to do.