Skip to content

Commit 2376638

Browse files
authored
perf(doctrine): don't load every value for a non-resource collection (#5922)
1 parent b101788 commit 2376638

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/Doctrine/EventListener/PurgeHttpCacheListener.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ private function gatherRelationTags(EntityManagerInterface $em, object $entity):
124124
{
125125
$associationMappings = $em->getClassMetadata(ClassUtils::getClass($entity))->getAssociationMappings();
126126
foreach (array_keys($associationMappings) as $property) {
127+
if (
128+
\array_key_exists('targetEntity', $associationMappings[$property])
129+
&& !$this->resourceClassResolver->isResourceClass($associationMappings[$property]['targetEntity'])) {
130+
return;
131+
}
127132
if ($this->propertyAccessor->isReadable($entity, $property)) {
128133
$this->addTagsFor($this->propertyAccessor->getValue($entity, $property));
129134
}

tests/Doctrine/EventListener/PurgeHttpCacheListenerTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,16 @@ public function testNotAResourceClass(): void
201201
// @phpstan-ignore-next-line
202202
$dummyClassMetadata->associationMappings = [
203203
'notAResource' => [],
204+
'collectionOfNotAResource' => ['targetEntity' => NotAResource::class],
204205
];
205206
$emProphecy->getClassMetadata(ContainNonResource::class)->willReturn($dummyClassMetadata);
206207
$eventArgs = new OnFlushEventArgs($emProphecy->reveal());
207208

208209
$propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class);
209210
$propertyAccessorProphecy->isReadable(Argument::type(ContainNonResource::class), 'notAResource')->willReturn(true);
211+
$propertyAccessorProphecy->isReadable(Argument::type(ContainNonResource::class), 'collectionOfNotAResource')->shouldNotBeCalled();
210212
$propertyAccessorProphecy->getValue(Argument::type(ContainNonResource::class), 'notAResource')->shouldBeCalled()->willReturn($nonResource);
213+
$propertyAccessorProphecy->getValue(Argument::type(ContainNonResource::class), 'collectionOfNotAResource')->shouldNotBeCalled();
211214

212215
$listener = new PurgeHttpCacheListener($purgerProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal());
213216
$listener->onFlush($eventArgs);

0 commit comments

Comments
 (0)