Skip to content

Commit

Permalink
Merge pull request #705 from favicode/fix/additional-check-for-purge-…
Browse files Browse the repository at this point in the history
…observer

Additional check for tag purge
  • Loading branch information
harmony7 authored Nov 6, 2024
2 parents 7feb1ea + b62baa9 commit cf94ebf
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Observer/InvalidateVarnishObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ public function execute(\Magento\Framework\Event\Observer $observer): void
continue;
}
$tag = $this->cacheTags->convertCacheTags($tag);

if (!$this->isTagAllowed($tag)) {
continue;
}

if (!in_array($tag, $this->alreadyPurged)) {
$tags[] = $tag;
$this->alreadyPurged[] = $tag;
Expand Down Expand Up @@ -113,4 +118,24 @@ private function canPurgeObject(\Magento\Framework\DataObject\IdentityInterface
}
return true;
}

/**
* Additional validation since IdentityInterface can pass canPurgeObject check (e.g. ProductRuleIndexer), but still
* hold tags of products or categories
*
* @param string $tag
* @return bool
*/
private function isTagAllowed(string $tag)
{
if ($tag === \Magento\Catalog\Model\Category::CACHE_TAG && !$this->config->canPurgeCatalogCategory()) {
return false;
}

if ($tag === \Magento\Catalog\Model\Product::CACHE_TAG && !$this->config->canPurgeCatalogProduct()) {
return false;
}

return true;
}
}

0 comments on commit cf94ebf

Please sign in to comment.