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

Improved performance of product category rewrites (disabled product & categories and product_use_categories) #3267

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
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
37 changes: 37 additions & 0 deletions app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Seo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* OpenMage
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available at https://opensource.org/license/osl-3-0-php
*
* @category Mage
* @package Mage_Adminhtml
* @copyright Copyright (c) 2006-2020 Magento, Inc. (http://www.magento.com)
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

/**
* @category Mage
* @package Mage_Adminhtml
*/
class Mage_Adminhtml_Model_System_Config_Backend_Seo extends Mage_Core_Model_Config_Data
{
/**
* Refresh categories and products url rewrites if configuration was changed
*/
protected function _afterSave()
{
if ($this->isValueChanged()) {
Mage::getModel('index/indexer')
->getProcessByCode(Mage_Catalog_Helper_Category_Flat::CATALOG_CATEGORY_FLAT_PROCESS_CODE)
->changeStatus(Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX);

Mage::getModel('index/indexer')
->getProcessByCode(Mage_Catalog_Helper_Product_Flat::CATALOG_FLAT_PROCESS_CODE)
->changeStatus(Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX);
}
return $this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@
class Mage_Adminhtml_Model_System_Config_Backend_Seo_Product extends Mage_Core_Model_Config_Data
{
/**
* Refresh category url rewrites if configuration was changed
* Refresh products url rewrites if configuration was changed
*
* @return $this
*/
protected function _afterSave()
{
if ($this->isValueChanged()) {
Mage::getModel('index/indexer')
->getProcessByCode(Mage_Catalog_Helper_Product_Flat::CATALOG_FLAT_PROCESS_CODE)
->changeStatus(Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX);
}

return $this;
}
}
43 changes: 36 additions & 7 deletions app/code/core/Mage/Catalog/Model/Indexer/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class Mage_Catalog_Model_Indexer_Url extends Mage_Index_Model_Indexer_Abstract
*/
protected $_matchedEntities = [
Mage_Catalog_Model_Product::ENTITY => [
Mage_Index_Model_Event::TYPE_SAVE
Mage_Index_Model_Event::TYPE_SAVE,
Mage_Index_Model_Event::TYPE_MASS_ACTION
],
Mage_Catalog_Model_Category::ENTITY => [
Mage_Index_Model_Event::TYPE_SAVE
Expand Down Expand Up @@ -173,12 +174,36 @@ protected function _registerEvent(Mage_Index_Model_Event $event)
protected function _registerProductEvent(Mage_Index_Model_Event $event)
{
$product = $event->getDataObject();
$dataChange = $product->dataHasChangedFor('url_key')
|| $product->getIsChangedCategories()
|| $product->getIsChangedWebsites();
$dataChange = false;
$products = [];

if ($product instanceof Mage_Catalog_Model_Product_Action) {
$attributesData = $product->getData('attributes_data');
$productsIds = $product->getData('product_ids');
$dataChange = isset($attributesData['status']) && isset($productsIds) && count($productsIds) > 0;
if ($dataChange) {
$products = Mage::getModel('catalog/product')->getCollection()
->addFieldToFilter('entity_id', ['in'=> $productsIds]);
} else {
return;
}
}

if ($product instanceof Mage_Catalog_Model_Product) {
$dataChange =
(
$product->dataHasChangedFor('url_key')
|| $product->dataHasChangedFor('status')
|| $product->getIsChangedCategories()
|| $product->getIsChangedWebsites()
) && !$product->getExcludeUrlRewrite();
$products = [$product];
}

if (!$product->getExcludeUrlRewrite() && $dataChange) {
$event->addNewData('rewrite_product_ids', [$product->getId()]);
if ($dataChange) {
foreach ($products as $product) {
$event->addNewData('rewrite_product_ids', [$product->getId()]);
}
}
}

Expand All @@ -191,7 +216,11 @@ protected function _registerCategoryEvent(Mage_Index_Model_Event $event)
{
$category = $event->getDataObject();
if (!$category->getInitialSetupFlag() && $category->getLevel() > 1) {
if ($category->dataHasChangedFor('url_key') || $category->getIsChangedProductList()) {
if (
$category->dataHasChangedFor('url_key')
|| $category->getIsChangedProductList()
|| $category->dataHasChangedFor('is_active')
) {
$event->addNewData('rewrite_category_ids', [$category->getId()]);
}
/**
Expand Down
Loading