Extract duplicated query from stats controller

This does include a bit of a simplification which assumes that there aren't any orphan
taggings for a user.