Refactor hidden doc middleware

Makes it slightly clearer what's going on with the two separate queries
we do to get the hidden docs for a collection.