Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Port cache invalidation to 2.x #369

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tunght13488
Copy link

No description provided.

Copy link

@pablofmorales pablofmorales left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix the issue in our end, looks good to. me

@@ -53,11 +62,13 @@ public function execute(array $ids)
foreach ($stores as $store) {
$this->getIndexerHandler()->saveIndex($this->rebuild((int) $store->getId(), []), $store);
$this->getIndexerHandler()->cleanUpByTransactionKey($store);
$this->cacheProcessor->cleanCacheByTags($store->getId(), [$this->getIndexerHandler()->getTypeName()]);
Copy link

@sarron93 sarron93 Feb 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that you need add checking for

$cacheTags = $this-> cacheProcessor->getCacheTags();
isset($cacheTags[$this->getIndexerHandler()];

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
} else {
foreach ($stores as $store) {
$this->getIndexerHandler()->createIndex($store);
$this->getIndexerHandler()->saveIndex($this->rebuild((int) $store->getId(), []), $store);
$this->cacheProcessor->cleanCacheByTags($store->getId(), [$this->getIndexerHandler()->getTypeName()]);
Copy link

@sarron93 sarron93 Feb 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that you need add checking for

$cacheTags = $this-> cacheProcessor->getCacheTags();
isset($cacheTags[$this->getTypeName()];
and set to second params $cacheTags[$this->getIndexerHandler()->getTypeName()] 

because cleanCacheByTags method don't check cache tag value

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -22,6 +52,7 @@ public function execute(array $ids)
foreach ($stores as $store) {
$this->getIndexerHandler()->saveIndex($this->rebuild((int) $store->getId(), $ids), $store);
$this->getIndexerHandler()->cleanUpByTransactionKey($store, $ids);
$this->cacheProcessor->cleanCacheByDocIds($store->getId(), $this->getIndexerHandler()->getTypeName(), $ids);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$cacheTags = $this->cacheProcessor->getCacheTags();
if (isset($cacheTags[$this->getIndexerHandler()->getTypeName()])) {
       $this->cacheProcessor->cleanCacheByDocIds(
              $store->getId(),
              $this->getIndexerHandler()->getTypeName(),
              $ids
       );
 } 

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

@mkucmus mkucmus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Little data validation and will be a 🚀

@rfaa-se
Copy link

rfaa-se commented Mar 17, 2021

Hi, any progress with getting this merged? :)

@rfaa-se
Copy link

rfaa-se commented Mar 18, 2021

Hi @tunght13488, I tried your latest changes and they are working a lot better. However there is still one issue I found, when adding a new product in magento I cannot see it when viewing the categories in vue storefront. I need to update an old product before it is displayed. Entering the url to the new product works though.
I haven't looked at the code but perhaps when adding a new product it's not updating the related categories?

@tunght13488
Copy link
Author

Hi @tunght13488, I tried your latest changes and they are working a lot better. However there is still one issue I found, when adding a new product in magento I cannot see it when viewing the categories in vue storefront. I need to update an old product before it is displayed. Entering the url to the new product works though.
I haven't looked at the code but perhaps when adding a new product it's not updating the related categories?

This PR only tries to port the existing cache invalidation logic into 2.x, not fixing anything

For your case I suggest looking into index table. Adding new product should add some changelog to vsbridge product index

@@ -1,3 +1,4 @@
.idea
composer.phar
/vendor/
composer.lock
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this shouldn't be ignored

use Magento\Framework\Event\ManagerInterface as EventManager;
use Magento\Framework\HTTP\Adapter\CurlFactory;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong order. Imports should be alphabetical

if ($this->config->clearCache($storeId)) {
$cacheTags = implode(',', $tags);
$cacheInvalidateUrl = $this->getInvalidateCacheUrl($storeId) . $cacheTags;
$cacheTags = array_intersect($tags, $this->getCacheTags());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be:
$cacheTags = array_intersect_key($this->getCacheTags(), array_flip($tags));

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants