|
22 | 22 | use Doctrine\ORM\PersistentCollection;
|
23 | 23 | use Doctrine\ORM\Persisters\Entity\EntityPersister;
|
24 | 24 | use Doctrine\ORM\Proxy\DefaultProxyClassNameResolver;
|
| 25 | +use Doctrine\ORM\Query\FilterCollection; |
25 | 26 | use Doctrine\ORM\UnitOfWork;
|
26 | 27 |
|
27 | 28 | use function array_merge;
|
| 29 | +use function func_get_args; |
28 | 30 | use function serialize;
|
29 | 31 | use function sha1;
|
30 | 32 |
|
@@ -62,6 +64,9 @@ abstract class AbstractEntityPersister implements CachedEntityPersister
|
62 | 64 | /** @var Cache */
|
63 | 65 | protected $cache;
|
64 | 66 |
|
| 67 | + /** @var FilterCollection */ |
| 68 | + protected $filters; |
| 69 | + |
65 | 70 | /** @var CacheLogger|null */
|
66 | 71 | protected $cacheLogger;
|
67 | 72 |
|
@@ -91,6 +96,7 @@ public function __construct(EntityPersister $persister, Region $region, EntityMa
|
91 | 96 | $this->region = $region;
|
92 | 97 | $this->persister = $persister;
|
93 | 98 | $this->cache = $em->getCache();
|
| 99 | + $this->filters = $em->getFilters(); |
94 | 100 | $this->regionName = $region->getName();
|
95 | 101 | $this->uow = $em->getUnitOfWork();
|
96 | 102 | $this->metadataFactory = $em->getMetadataFactory();
|
@@ -261,7 +267,7 @@ protected function getHash($query, $criteria, ?array $orderBy = null, $limit = n
|
261 | 267 | ? $this->persister->expandCriteriaParameters($criteria)
|
262 | 268 | : $this->persister->expandParameters($criteria);
|
263 | 269 |
|
264 |
| - return sha1($query . serialize($params) . serialize($orderBy) . $limit . $offset); |
| 270 | + return sha1($query . serialize($params) . serialize($orderBy) . $limit . $offset . $this->filters->getHash()); |
265 | 271 | }
|
266 | 272 |
|
267 | 273 | /**
|
@@ -524,7 +530,7 @@ public function loadManyToManyCollection(array $assoc, $sourceEntity, Persistent
|
524 | 530 | }
|
525 | 531 |
|
526 | 532 | $ownerId = $this->uow->getEntityIdentifier($collection->getOwner());
|
527 |
| - $key = $this->buildCollectionCacheKey($assoc, $ownerId); |
| 533 | + $key = $this->buildCollectionCacheKey($assoc, $ownerId, $this->filters->getHash()); |
528 | 534 | $list = $persister->loadCollectionCache($collection, $key);
|
529 | 535 |
|
530 | 536 | if ($list !== null) {
|
@@ -559,7 +565,7 @@ public function loadOneToManyCollection(array $assoc, $sourceEntity, PersistentC
|
559 | 565 | }
|
560 | 566 |
|
561 | 567 | $ownerId = $this->uow->getEntityIdentifier($collection->getOwner());
|
562 |
| - $key = $this->buildCollectionCacheKey($assoc, $ownerId); |
| 568 | + $key = $this->buildCollectionCacheKey($assoc, $ownerId, $this->filters->getHash()); |
563 | 569 | $list = $persister->loadCollectionCache($collection, $key);
|
564 | 570 |
|
565 | 571 | if ($list !== null) {
|
@@ -611,12 +617,15 @@ public function refresh(array $id, $entity, $lockMode = null)
|
611 | 617 | *
|
612 | 618 | * @return CollectionCacheKey
|
613 | 619 | */
|
614 |
| - protected function buildCollectionCacheKey(array $association, $ownerId) |
| 620 | + protected function buildCollectionCacheKey(array $association, $ownerId/*, string $filterHash */) |
615 | 621 | {
|
| 622 | + $filterHash = (string) (func_get_args()[2] ?? ''); // todo: move to argument in next major release |
| 623 | + |
616 | 624 | return new CollectionCacheKey(
|
617 | 625 | $this->metadataFactory->getMetadataFor($association['sourceEntity'])->rootEntityName,
|
618 | 626 | $association['fieldName'],
|
619 |
| - $ownerId |
| 627 | + $ownerId, |
| 628 | + $filterHash |
620 | 629 | );
|
621 | 630 | }
|
622 | 631 | }
|
0 commit comments