24
24
use Doctrine \ORM \PersistentCollection ;
25
25
use Doctrine \ORM \Persisters \Entity \EntityPersister ;
26
26
use Doctrine \ORM \Proxy \DefaultProxyClassNameResolver ;
27
+ use Doctrine \ORM \Query \FilterCollection ;
27
28
use Doctrine \ORM \Query \ResultSetMapping ;
28
29
use Doctrine \ORM \UnitOfWork ;
29
30
30
31
use function array_merge ;
32
+ use function func_get_args ;
31
33
use function serialize ;
32
34
use function sha1 ;
33
35
@@ -43,6 +45,7 @@ abstract class AbstractEntityPersister implements CachedEntityPersister
43
45
protected TimestampCacheKey $ timestampKey ;
44
46
protected EntityHydrator $ hydrator ;
45
47
protected Cache $ cache ;
48
+ protected FilterCollection $ filters ;
46
49
protected CacheLogger |null $ cacheLogger = null ;
47
50
protected string $ regionName ;
48
51
@@ -64,6 +67,7 @@ public function __construct(
64
67
$ cacheFactory = $ cacheConfig ->getCacheFactory ();
65
68
66
69
$ this ->cache = $ em ->getCache ();
70
+ $ this ->filters = $ em ->getFilters ();
67
71
$ this ->regionName = $ region ->getName ();
68
72
$ this ->uow = $ em ->getUnitOfWork ();
69
73
$ this ->metadataFactory = $ em ->getMetadataFactory ();
@@ -215,7 +219,7 @@ protected function getHash(
215
219
? $ this ->persister ->expandCriteriaParameters ($ criteria )
216
220
: $ this ->persister ->expandParameters ($ criteria );
217
221
218
- return sha1 ($ query . serialize ($ params ) . serialize ($ orderBy ) . $ limit . $ offset );
222
+ return sha1 ($ query . serialize ($ params ) . serialize ($ orderBy ) . $ limit . $ offset . $ this -> filters -> getHash () );
219
223
}
220
224
221
225
/**
@@ -472,7 +476,7 @@ public function loadManyToManyCollection(
472
476
}
473
477
474
478
$ ownerId = $ this ->uow ->getEntityIdentifier ($ collection ->getOwner ());
475
- $ key = $ this ->buildCollectionCacheKey ($ assoc , $ ownerId );
479
+ $ key = $ this ->buildCollectionCacheKey ($ assoc , $ ownerId, $ this -> filters -> getHash () );
476
480
$ list = $ persister ->loadCollectionCache ($ collection , $ key );
477
481
478
482
if ($ list !== null ) {
@@ -503,7 +507,7 @@ public function loadOneToManyCollection(
503
507
}
504
508
505
509
$ ownerId = $ this ->uow ->getEntityIdentifier ($ collection ->getOwner ());
506
- $ key = $ this ->buildCollectionCacheKey ($ assoc , $ ownerId );
510
+ $ key = $ this ->buildCollectionCacheKey ($ assoc , $ ownerId, $ this -> filters -> getHash () );
507
511
$ list = $ persister ->loadCollectionCache ($ collection , $ key );
508
512
509
513
if ($ list !== null ) {
@@ -546,12 +550,15 @@ public function refresh(array $id, object $entity, LockMode|int|null $lockMode =
546
550
}
547
551
548
552
/** @param array<string, mixed> $ownerId */
549
- protected function buildCollectionCacheKey (AssociationMapping $ association , array $ ownerId ): CollectionCacheKey
553
+ protected function buildCollectionCacheKey (AssociationMapping $ association , array $ ownerId, /* string $filterHash */ ): CollectionCacheKey
550
554
{
555
+ $ filterHash = (string ) (func_get_args ()[2 ] ?? '' ); // todo: move to argument in next major release
556
+
551
557
return new CollectionCacheKey (
552
558
$ this ->metadataFactory ->getMetadataFor ($ association ->sourceEntity )->rootEntityName ,
553
559
$ association ->fieldName ,
554
560
$ ownerId ,
561
+ $ filterHash ,
555
562
);
556
563
}
557
564
}
0 commit comments