PersistentCollection::count() improvements

`PersistentCollection::count()` method consumes too much memory and time when there are many referenced documents. It queries and hydrates referenced documents and uses `ArrayCollection::count()` method to get quantity of result elements instead of executing `count` command into database.

This PR improves `PersistentCollection::count()` method. New behavior:
* it executes database `count` command when collection is `InverseSide` and not inititalized yet
* uses `ArrayCollection::count()` method in an opposite way