Skip to content

Commit 375fd4c

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

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Magento\Framework\Serialize\Serializer\Json;
1919
use Magento\UrlRewrite\Controller\Adminhtml\Url\Rewrite;
2020
use Magento\UrlRewrite\Model\ResourceModel\UrlRewriteCollection;
21+
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite as UrlRewriteService;
2122

2223
/**
2324
* UrlRewrite model class
@@ -140,9 +141,9 @@ public function setMetadata($metadata)
140141
*
141142
* @param string $path
142143
* @param int $storeId
143-
* @return UrlRewrite|null
144+
* @return UrlRewriteService|null
144145
*/
145-
private function getFinalTargetUrlRewrite(string $path, int $storeId): ?UrlRewrite
146+
private function getFinalTargetUrlRewrite(string $path, int $storeId): ?UrlRewriteService
146147
{
147148
$urlRewriteTarget = $this->urlFinder->findOneByData(
148149
[
@@ -166,7 +167,7 @@ private function getFinalTargetUrlRewrite(string $path, int $storeId): ?UrlRewri
166167
/**
167168
* Clean the cache for entities affected by current rewrite
168169
*/
169-
private function cleanEntitiesCache()
170+
public function cleanEntitiesCache()
170171
{
171172
if (!$this->isEmpty()) {
172173
if ($this->getEntityType() === Rewrite::ENTITY_TYPE_CUSTOM) {
@@ -215,7 +216,7 @@ private function cleanCacheForEntity(string $entityType, int $entityId)
215216
*/
216217
public function afterDelete()
217218
{
218-
$this->cleanEntitiesCache();
219+
$this->_getResource()->addCommitCallback([$this, 'cleanEntitiesCache']);
219220
return parent::afterDelete();
220221
}
221222

@@ -224,7 +225,7 @@ public function afterDelete()
224225
*/
225226
public function afterSave()
226227
{
227-
$this->cleanEntitiesCache();
228+
$this->_getResource()->addCommitCallback([$this, 'cleanEntitiesCache']);
228229
return parent::afterSave();
229230
}
230231
}

0 commit comments

Comments
 (0)