Skip to content

Commit ecb3f6c

Browse files
authored
fix(httpcache): only map entites that are persisted
1 parent 0203852 commit ecb3f6c

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/Symfony/Bundle/Resources/config/doctrine_orm_http_cache_purger.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<argument type="service" id="api_platform.iri_converter" />
1414
<argument type="service" id="api_platform.resource_class_resolver" />
1515
<argument type="service" id="api_platform.property_accessor" />
16-
<argument type="service" id="object_mapper" on-invalid="null" />
16+
<argument type="service" id="api_platform.object_mapper" on-invalid="null" />
1717
<tag name="doctrine.event_listener" event="preUpdate" />
1818
<tag name="doctrine.event_listener" event="onFlush" />
1919
<tag name="doctrine.event_listener" event="postFlush" />

src/Symfony/Doctrine/EventListener/PurgeHttpCacheListener.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,14 @@ public function onFlush(OnFlushEventArgs $eventArgs): void
8484
$uow = $em->getUnitOfWork();
8585

8686
foreach ($uow->getScheduledEntityInsertions() as $entity) {
87-
$this->gatherResourceAndItemTags($entity, false);
87+
// For new entities, only purge the collection IRI
88+
try {
89+
if ($this->resourceClassResolver->isResourceClass($this->getObjectClass($entity))) {
90+
$iri = $this->iriConverter->getIriFromResource($entity, UrlGeneratorInterface::ABS_PATH, new GetCollection());
91+
$this->tags[$iri] = $iri;
92+
}
93+
} catch (OperationNotFoundException|InvalidArgumentException) {
94+
}
8895
$this->gatherRelationTags($em, $entity);
8996
}
9097

0 commit comments

Comments
 (0)