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

Improve performance of product category rewrites (disabled product & categories and product_use_categories) #1405

Closed
46 changes: 46 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,46 @@
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* 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 through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magento.com for more information.
*
* @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)
*/


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 @@ -27,12 +27,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 @@ -47,7 +47,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 @@ -180,12 +181,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 @@ -198,7 +223,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