don't bother with count() if a limit has already been set

the constructed query for count below strips off any limit and offset, and if limit is specified without offset, it returns the whole count, not the limited count.