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

Config cache for system.xml loader: Speed improvement #1916

Merged
merged 10 commits into from
Jun 9, 2022
66 changes: 63 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,67 @@ public function getTabs()
return $this->_tabs;
}

/**
* @param array $params
*/
public function __construct(array $params = array())
{
$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()) {
/** @var Mage_Core_Model_Config_Base $config */
elidrissidev marked this conversation as resolved.
Show resolved Hide resolved
$this->_config = Mage::getConfig()->loadModulesConfiguration('system.xml')
->applyExtends();
if ($usesCache) {
$this->saveCache();
}
}
fballiano marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* @param $tags
elidrissidev marked this conversation as resolved.
Show resolved Hide resolved
* @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 ($this->_config->loadString($xmlString)) {
luigifab marked this conversation as resolved.
Show resolved Hide resolved
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>
luigifab marked this conversation as resolved.
Show resolved Hide resolved
<tags>CONFIG</tags>
</config>
<layout translate="label,description" module="core">
Expand Down