Modify count_by and count_all to support soft deletes.