Skip to content

Commit

Permalink
Cache for system.xml loader: Speed improvement (#1916)
Browse files Browse the repository at this point in the history
  • Loading branch information
lamskoy authored Jun 9, 2022
1 parent 3005c60 commit 14cf6fa
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ Most important changes will be listed here, all other changes since `19.4.0` can

### Between Magento 1.9.4.5 and OpenMage 19.x

Bug fixes and PHP 7.x and 8.0 compatibility.
- bug fixes and PHP 7.x and 8.0 compatibility
- added config cache for system.xml #1916

### Between OpenMage 19.x and 20.x

Expand Down
62 changes: 59 additions & 3 deletions app/code/core/Mage/Adminhtml/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@
*/
class Mage_Adminhtml_Model_Config extends Varien_Simplexml_Config
{
/**
* @var string
*/
protected $_cacheId = 'mage_adminhtml_config_system_xml';

/**
* @var Mage_Core_Model_Config_Base
*/
protected $_config;

/**
* Enter description here...
Expand Down Expand Up @@ -80,16 +89,63 @@ public function getTabs()
return $this->_tabs;
}

public function __construct()
{
$this->_cacheChecksum = null;
$this->setCache(Mage::app()->getCache());
$this->setCacheTags([Mage_Core_Model_Config::CACHE_TAG]);
$usesCache = Mage::app()->useCache('config');
if (!$usesCache || !$this->loadCache()) {
$this->_config = Mage::getConfig()->loadModulesConfiguration('system.xml')
->applyExtends();
if ($usesCache) {
$this->saveCache();
}
}
}

/**
* @param array|null $tags
* @return $this|Mage_Adminhtml_Model_Config
*/
public function saveCache($tags=null)
{
if ($this->getCacheSaved()) {
return $this;
}
if (is_null($tags)) {
$tags = $this->_cacheTags;
}
$xmlString = $this->_config->getXmlString();
$this->_saveCache($xmlString, $this->getCacheId(), $tags, $this->getCacheLifetime());
$this->setCacheSaved(true);
return $this;
}

/**
* @return bool
*/
public function loadCache()
{
$xmlString = $this->_loadCache($this->getCacheId());
$class = Mage::getConfig()->getModelClassName('core/config_base');
$this->_config = new $class();
libxml_use_internal_errors(true);
if (!empty($xmlString) && $this->_config->loadString($xmlString)) {
return true;
}
libxml_clear_errors();
return false;
}

/**
* Init modules configuration
*
* @return void
*/
protected function _initSectionsAndTabs()
{
$config = Mage::getConfig()->loadModulesConfiguration('system.xml')
->applyExtends();

$config = $this->_config;
Mage::dispatchEvent('adminhtml_init_system_config', array('config' => $config));
$this->_sections = $config->getNode('sections');
$this->_tabs = $config->getNode('tabs');
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
<types>
<config translate="label,description" module="core">
<label>Configuration</label>
<description>System(config.xml, local.xml) and modules configuration files(config.xml).</description>
<description>System (config.xml, local.xml) and modules configuration files (config.xml, system.xml).</description>
<tags>CONFIG</tags>
</config>
<layout translate="label,description" module="core">
Expand Down
1 change: 1 addition & 0 deletions app/locale/en_US/Mage_Core.csv
Original file line number Diff line number Diff line change
Expand Up @@ -433,3 +433,4 @@
"You will have to log in after you save your custom admin path.","You will have to log in after you save your custom admin path."
"Your design change for the specified store intersects with another one, please specify another date range.","Your design change for the specified store intersects with another one, please specify another date range."
"database ""%s""","database ""%s"""
"System (config.xml, local.xml) and modules configuration files (config.xml, system.xml).","System (config.xml, local.xml) and modules configuration files (config.xml, system.xml)."

0 comments on commit 14cf6fa

Please sign in to comment.