DB Optimizations

This branch contains some database improvements including eliminating n+1 queries and adding some cache_counter columns.

These changes eliminate 100's of queries per request for large installations. 

More work remains for future pull requests.