Extract duplicated query

This includes a bit of a simplification which assumes that there aren't
any orphan taggings for a user.
Merge pull request #160 from kytrinyx/tag-counts

Extract duplicated query from stats controller