Query optimizations

Thanks to #1516, I got nerd sniped a bit and did some query-optimization.  Should hopefully speed up the dashboard a bit.  Depends on #1502, mostly just to avoid merge conflicts.