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