diff --git a/README.md b/README.md index 2698197cd11..8b7c7c1dd32 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/app/code/core/Mage/Adminhtml/Model/Config.php b/app/code/core/Mage/Adminhtml/Model/Config.php index e4f77ff0650..68deefd43c0 100644 --- a/app/code/core/Mage/Adminhtml/Model/Config.php +++ b/app/code/core/Mage/Adminhtml/Model/Config.php @@ -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... @@ -80,6 +89,55 @@ 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 * @@ -87,9 +145,7 @@ public function getTabs() */ 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'); diff --git a/app/code/core/Mage/Core/etc/config.xml b/app/code/core/Mage/Core/etc/config.xml index 3f4a0ed80a6..ff5e50bd201 100644 --- a/app/code/core/Mage/Core/etc/config.xml +++ b/app/code/core/Mage/Core/etc/config.xml @@ -122,7 +122,7 @@ - System(config.xml, local.xml) and modules configuration files(config.xml). + System (config.xml, local.xml) and modules configuration files (config.xml, system.xml). CONFIG diff --git a/app/locale/en_US/Mage_Core.csv b/app/locale/en_US/Mage_Core.csv index b406d43393b..9e74c93d986 100644 --- a/app/locale/en_US/Mage_Core.csv +++ b/app/locale/en_US/Mage_Core.csv @@ -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)."