DDC-2865: [GH-882] Efficient counting on Criteria #3576

Closed
opened 2026-01-22 14:22:57 +01:00 by admin · 3 comments
Owner

Originally created by @doctrinebot on GitHub (Dec 19, 2013).

Originally assigned to: @guilhermeblanco on GitHub.

Jira issue originally created by user @doctrinebot:

This issue is created automatically through a Github pull request on behalf of bakura10:

Url: https://github.com/doctrine/doctrine2/pull/882

Message:

Hi,

This is an attempt to solve this very annoying issue: http://www.doctrine-project.org/jira/browse/DDC-2217

I'm not sure about my solution as I'm not really into Doctrine internals.

Use case

I have a library that is based exclusively on Criteria API. A Paginator adapter uses an empty Criteria to count how many elements are in the collection. However, EntityRepository's matching method always initialize the whole collection into an ArrayCollection. This is unusable in most cases and make the API unusable for my use case.

Solution

I've created a new LazyCollectionCriteria that implements an efficient count. I think the cleanest solution would be to add a method to the Selectable interface: with a count method. But I think this is not possible now, unfortunately.

If the solution seems nice to you, I'll write the tests.

ping @ocramius, @mac_nibblet and @thinkscape (this should make ZfrRest usable :D)

Originally created by @doctrinebot on GitHub (Dec 19, 2013). Originally assigned to: @guilhermeblanco on GitHub. Jira issue originally created by user @doctrinebot: This issue is created automatically through a Github pull request on behalf of bakura10: Url: https://github.com/doctrine/doctrine2/pull/882 Message: Hi, This is an attempt to solve this very annoying issue: http://www.doctrine-project.org/jira/browse/[DDC-2217](http://www.doctrine-project.org/jira/browse/DDC-2217) I'm not sure about my solution as I'm not really into Doctrine internals. # Use case I have a library that is based exclusively on Criteria API. A Paginator adapter uses an empty Criteria to count how many elements are in the collection. However, EntityRepository's matching method always initialize the whole collection into an ArrayCollection. This is unusable in most cases and make the API unusable for my use case. # Solution I've created a new LazyCollectionCriteria that implements an efficient count. I think the cleanest solution would be to add a method to the Selectable interface: with a count method. But I think this is not possible now, unfortunately. If the solution seems nice to you, I'll write the tests. ping @ocramius, @mac_nibblet and @thinkscape (this should make ZfrRest usable :D)
admin added the Improvement label 2026-01-22 14:22:57 +01:00
admin closed this issue 2026-01-22 14:22:57 +01:00
Author
Owner

@doctrinebot commented on GitHub (Dec 19, 2013):

@doctrinebot commented on GitHub (Dec 19, 2013): - is referenced by [DDC-2217: Return a lazy collection from PersistentCollection::match($criteria)](http://www.doctrine-project.org/jira/browse/DDC-2217)
Author
Owner

@doctrinebot commented on GitHub (May 16, 2014):

Comment created by @doctrinebot:

A related Github Pull-Request [GH-882] was closed:
https://github.com/doctrine/doctrine2/pull/882

@doctrinebot commented on GitHub (May 16, 2014): Comment created by @doctrinebot: A related Github Pull-Request [GH-882] was closed: https://github.com/doctrine/doctrine2/pull/882
Author
Owner

@doctrinebot commented on GitHub (May 16, 2014):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (May 16, 2014): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#3576