Skip to content

Commit a1750ac

Browse files
committed
MC-39463: GraphQL caches urlResolver response and can return the old value after the url rewrite update
1 parent 253f0d2 commit a1750ac

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

app/code/Magento/UrlRewrite/Model/UrlRewrite.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -168,28 +168,30 @@ private function getFinalTargetUrlRewrite(string $path, int $storeId): ?UrlRewri
168168
*/
169169
private function cleanEntitiesCache()
170170
{
171-
if ($this->getEntityType() === Rewrite::ENTITY_TYPE_CUSTOM) {
172-
$urlRewrite = $this->getFinalTargetUrlRewrite(
173-
$this->getTargetPath(),
174-
(int)$this->getStoreId()
175-
);
171+
if (!$this->isEmpty()) {
172+
if ($this->getEntityType() === Rewrite::ENTITY_TYPE_CUSTOM) {
173+
$urlRewrite = $this->getFinalTargetUrlRewrite(
174+
$this->getTargetPath(),
175+
(int)$this->getStoreId()
176+
);
176177

177-
if ($urlRewrite) {
178-
$this->cleanCacheForEntity($urlRewrite->getEntityType(), (int) $urlRewrite->getEntityId());
179-
}
178+
if ($urlRewrite) {
179+
$this->cleanCacheForEntity($urlRewrite->getEntityType(), (int) $urlRewrite->getEntityId());
180+
}
180181

181-
if ($this->getOrigData() && $this->getOrigData('target_path') !== $this->getTargetPath()) {
182-
$origUrlRewrite = $this->getFinalTargetUrlRewrite(
183-
$this->getOrigData('target_path'),
184-
(int)$this->getOrigData('store_id')
185-
);
182+
if ($this->getOrigData() && $this->getOrigData('target_path') !== $this->getTargetPath()) {
183+
$origUrlRewrite = $this->getFinalTargetUrlRewrite(
184+
$this->getOrigData('target_path'),
185+
(int)$this->getOrigData('store_id')
186+
);
186187

187-
if ($origUrlRewrite) {
188-
$this->cleanCacheForEntity($origUrlRewrite->getEntityType(), (int) $origUrlRewrite->getEntityId());
188+
if ($origUrlRewrite) {
189+
$this->cleanCacheForEntity($origUrlRewrite->getEntityType(), (int) $origUrlRewrite->getEntityId());
190+
}
189191
}
192+
} else {
193+
$this->cleanCacheForEntity($this->getEntityType(), (int) $this->getEntityId());
190194
}
191-
} else {
192-
$this->cleanCacheForEntity($this->getEntityType(), (int) $this->getEntityId());
193195
}
194196
}
195197

0 commit comments

Comments
 (0)