File tree 5 files changed +29
-9
lines changed
5 files changed +29
-9
lines changed Original file line number Diff line number Diff line change 22
22
use function array_map ;
23
23
use function array_sum ;
24
24
use function assert ;
25
- use function count ;
26
25
use function is_string ;
27
26
28
27
/**
@@ -160,7 +159,7 @@ public function getIterator()
160
159
$ ids = array_map ('current ' , $ foundIdRows );
161
160
162
161
$ this ->appendTreeWalker ($ whereInQuery , WhereInWalker::class);
163
- $ whereInQuery ->setHint (WhereInWalker::HINT_PAGINATOR_ID_COUNT , count ( $ ids ) );
162
+ $ whereInQuery ->setHint (WhereInWalker::HINT_PAGINATOR_HAS_IDS , true );
164
163
$ whereInQuery ->setFirstResult (0 )->setMaxResults (null );
165
164
$ whereInQuery ->setCacheable ($ this ->query ->isCacheable ());
166
165
Original file line number Diff line number Diff line change 28
28
* The parameter namespace (dpid) is defined by
29
29
* the PAGINATOR_ID_ALIAS
30
30
*
31
- * The total number of parameters is retrieved from
32
- * the HINT_PAGINATOR_ID_COUNT query hint .
31
+ * The HINT_PAGINATOR_HAS_IDS query hint indicates whether there are
32
+ * any ids in the parameter at all .
33
33
*/
34
34
class WhereInWalker extends TreeWalkerAdapter
35
35
{
36
36
/**
37
37
* ID Count hint name.
38
38
*/
39
- public const HINT_PAGINATOR_ID_COUNT = 'doctrine.id.count ' ;
39
+ public const HINT_PAGINATOR_HAS_IDS = 'doctrine.paginator_has_ids ' ;
40
40
41
41
/**
42
42
* Primary key alias for query.
@@ -65,9 +65,9 @@ public function walkSelectStatement(SelectStatement $AST)
65
65
$ pathExpression = new PathExpression (PathExpression::TYPE_STATE_FIELD | PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION , $ rootAlias , $ identifierFieldName );
66
66
$ pathExpression ->type = $ pathType ;
67
67
68
- $ count = $ this ->_getQuery ()->getHint (self ::HINT_PAGINATOR_ID_COUNT );
68
+ $ hasIds = $ this ->_getQuery ()->getHint (self ::HINT_PAGINATOR_HAS_IDS );
69
69
70
- if ($ count > 0 ) {
70
+ if ($ hasIds ) {
71
71
$ arithmeticExpression = new ArithmeticExpression ();
72
72
$ arithmeticExpression ->simpleArithmeticExpression = new SimpleArithmeticExpression (
73
73
[$ pathExpression ]
Original file line number Diff line number Diff line change @@ -667,6 +667,27 @@ public function testPaginationWithSubSelectOrderByExpression($useOutputWalker, $
667
667
self ::assertCount (9 , $ paginator ->getIterator ());
668
668
}
669
669
670
+ public function testDifferentResultLengthsDoNotRequireExtraQueryCacheEntries (): void
671
+ {
672
+ $ dql = 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id >= :id ' ;
673
+ $ query = $ this ->_em ->createQuery ($ dql );
674
+ $ query ->setMaxResults (10 );
675
+
676
+ $ query ->setParameter ('id ' , 1 );
677
+ $ paginator = new Paginator ($ query );
678
+ $ paginator ->getIterator (); // exercise the Paginator
679
+
680
+ $ initialCount = count (self ::$ queryCache ->getValues ());
681
+
682
+ $ query ->setParameter ('id ' , 2 );
683
+ $ paginator = new Paginator ($ query );
684
+ $ paginator ->getIterator (); // exercise the Paginator again, with a smaller result set
685
+
686
+ $ newCount = count (self ::$ queryCache ->getValues ());
687
+
688
+ self ::assertSame ($ initialCount , $ newCount );
689
+ }
690
+
670
691
public function populate (): void
671
692
{
672
693
$ groups = [];
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ public function testDqlQueryTransformation(string $dql, string $expectedSql): vo
19
19
{
20
20
$ query = $ this ->entityManager ->createQuery ($ dql );
21
21
$ query ->setHint (Query::HINT_CUSTOM_TREE_WALKERS , [WhereInWalker::class]);
22
- $ query ->setHint (WhereInWalker::HINT_PAGINATOR_ID_COUNT , 10 );
22
+ $ query ->setHint (WhereInWalker::HINT_PAGINATOR_HAS_IDS , true );
23
23
24
24
$ result = (new Parser ($ query ))->parse ();
25
25
Original file line number Diff line number Diff line change @@ -74,7 +74,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
74
74
*
75
75
* @var CacheItemPoolInterface|null
76
76
*/
77
- private static $ queryCache = null ;
77
+ protected static $ queryCache = null ;
78
78
79
79
/**
80
80
* Shared connection when a TestCase is run alone (outside of its functional suite).
You can’t perform that action at this time.
0 commit comments