Don't query for objects in a response when we know the count is 0.

When building a paginated webapi response, we would always perform a
query for the count and a query for the objects. The latter query is
pointless if the count is 0, so only do it if we know there are objects
to fetch.