diff options
author | matt <matt@59fd770c-687e-43c8-a1e3-f5a4ff64c105> | 2009-05-05 03:09:06 +0400 |
---|---|---|
committer | matt <matt@59fd770c-687e-43c8-a1e3-f5a4ff64c105> | 2009-05-05 03:09:06 +0400 |
commit | 53a87e6f44e023a98609874da7dfcb93def5ac72 (patch) | |
tree | 181821f03fd10e6d9e724d591475ecab1c81841d /core | |
parent | cb346a4546a53bdc5054129d3331470cb3a447fc (diff) |
- improved Config.php: This slightly helps reducing the Zend overhead when accessing config entries hundreds of times.
Diffstat (limited to 'core')
-rw-r--r-- | core/Config.php | 75 |
1 files changed, 53 insertions, 22 deletions
diff --git a/core/Config.php b/core/Config.php index 90823ef9d2..39d3e7bea1 100644 --- a/core/Config.php +++ b/core/Config.php @@ -178,6 +178,7 @@ class Piwik_Config */ public function __set($name, $value) { + $this->cachedConfigArray = array(); $this->checkWritePermissionOnFile(); if(is_null($this->userConfig)) { @@ -206,6 +207,55 @@ class Piwik_Config return $enoughPermission; } + protected $cachedConfigArray = array(); + + /** + * Loop through the Default and the User configuration objects and cache them in arrays. + * This slightly helps reducing the Zend overhead when accessing config entries hundreds of times. + * @return void + */ + protected function cacheConfigArray() + { + $allSections = array(); + foreach($this->defaultConfig as $sectionName => $valueInDefaultConfig) + { + $allSections[] = $sectionName; + } + foreach($this->userConfig as $sectionName => $valueInUserConfig) + { + $allSections[] = $sectionName; + } + $allSections = array_unique($allSections); + + foreach($allSections as $sectionName) + { + $section = array(); + if(($valueInDefaultConfig = $this->defaultConfig->$sectionName) !== null) + { + $valueInDefaultConfig = $valueInDefaultConfig->toArray(); + $section = array_merge($section, $valueInDefaultConfig); + } + if( !is_null($this->userConfig) + && null !== ($valueInUserConfig = $this->userConfig->$sectionName)) + { + $valueInUserConfig = $valueInUserConfig->toArray(); + foreach($valueInUserConfig as $name => &$value) + { + if(is_array($value)) + { + $value = array_map("html_entity_decode", $value); + } + else + { + $value = html_entity_decode($value); + } + } + $section = array_merge($section, $valueInUserConfig); + } + $this->cachedConfigArray[$sectionName] = new Zend_Config($section); + } + } + /** * Called when getting a configuration value, eg. Zend_Registry::get('config')->superuser->login * @@ -216,29 +266,10 @@ class Piwik_Config */ public function __get($name) { - $section = array(); - if(null !== ($valueInDefaultConfig = $this->defaultConfig->$name)) + if(empty($this->cachedConfigArray)) { - $valueInDefaultConfig = $valueInDefaultConfig->toArray(); - $section = array_merge($section, $valueInDefaultConfig); - } - if( !is_null($this->userConfig) - && null !== ($valueInUserConfig = $this->userConfig->$name)) - { - $valueInUserConfig = $valueInUserConfig->toArray(); - foreach($valueInUserConfig as $name => &$value) - { - if(is_array($value)) - { - $value = array_map("html_entity_decode", $value); - } - else - { - $value = html_entity_decode($value); - } - } - $section = array_merge($section, $valueInUserConfig); + $this->cacheConfigArray(); } - return new Zend_Config($section); + return $this->cachedConfigArray[$name]; } } |