Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear category caches after product (mass)save #248

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions app/code/community/Lesti/Fpc/Model/Observer/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,11 @@ public function catalogProductSaveAfter($observer)
if ($product->getId()) {
$this->_getFpc()->clean(sha1('product_' . $product->getId()));

$origData = $product->getOrigData();
if (empty($origData)
|| (!empty($origData) && $product->dataHasChangedFor('status'))
) {
$categories = $product->getCategoryIds();
foreach ($categories as $categoryId) {
$this->_getFpc()->clean(
sha1('category_' . $categoryId)
);
}
$categories = $product->getCategoryIds();
foreach ($categories as $categoryId) {
$this->_getFpc()->clean(
sha1('category_' . $categoryId)
);
}
}
}
Expand Down Expand Up @@ -152,6 +147,14 @@ protected function _catalogProductSaveAfterMassAction(array $productIds)
$tags = array();
foreach ($productIds as $productId) {
$tags[] = sha1('product_' . $productId);

$product = Mage::getModel('catalog/product')->load($productId);
Copy link
Owner

Choose a reason for hiding this comment

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

Please do not load products in a loop.

Copy link
Author

Choose a reason for hiding this comment

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

Suggestions? Use a collection before the loop and load all $productIds?

Copy link

@hoanglonguit hoanglonguit Dec 21, 2016

Choose a reason for hiding this comment

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

My suggestion is query directly to database for getting categories, catalog_category_product table is a good start.

$categories = $product->getCategoryIds();
foreach ($categories as $categoryId) {
$this->_getFpc()->clean(
sha1('category_' . $categoryId)
);
}
}
$this->_getFpc()->clean($tags);
}
Expand Down