Remove n+1

some db optimizations mentioned in #386

most of the legwork was done by @phlipper. i simply did some cleanup and applied it to the newest master branch.

i'm splitting up the n+1 and counter cache into separate commits