Performance: Don't initialize configuration folders until they are needed

This commit is contained in:
Aleksander Machniak 2016-02-22 12:17:22 +01:00
parent cb7f4d635b
commit b6a9141764

View file

@ -58,8 +58,12 @@ class kolab_storage_config
/** /**
* Private constructor (finds default configuration folder as a config source) * Private constructor (finds default configuration folder as a config source)
*/ */
private function __construct() private function _init()
{ {
if ($this->enabled !== null) {
return $this->enabled;
}
// get all configuration folders // get all configuration folders
$this->folders = kolab_storage::get_folders(self::FOLDER_TYPE, false); $this->folders = kolab_storage::get_folders(self::FOLDER_TYPE, false);
@ -86,9 +90,7 @@ class kolab_storage_config
} }
// check if configuration folder exist // check if configuration folder exist
if ($this->default && $this->default->name) { return $this->enabled = $this->default && $this->default->name;
$this->enabled = true;
}
} }
/** /**
@ -98,7 +100,7 @@ class kolab_storage_config
*/ */
public function is_enabled() public function is_enabled()
{ {
return $this->enabled; return $this->_init();
} }
/** /**
@ -114,6 +116,10 @@ class kolab_storage_config
{ {
$list = array(); $list = array();
if (!$this->is_enabled()) {
return $list;
}
foreach ($this->folders as $folder) { foreach ($this->folders as $folder) {
// we only want to read from default folder // we only want to read from default folder
if ($default && !$folder->default) { if ($default && !$folder->default) {
@ -144,6 +150,10 @@ class kolab_storage_config
*/ */
public function get_object($uid, $default = false) public function get_object($uid, $default = false)
{ {
if (!$this->is_enabled()) {
return;
}
foreach ($this->folders as $folder) { foreach ($this->folders as $folder) {
// we only want to read from default folder // we only want to read from default folder
if ($default && !$folder->default) { if ($default && !$folder->default) {
@ -166,7 +176,7 @@ class kolab_storage_config
*/ */
public function save(&$object, $type) public function save(&$object, $type)
{ {
if (!$this->enabled) { if (!$this->is_enabled()) {
return false; return false;
} }
@ -207,7 +217,7 @@ class kolab_storage_config
*/ */
public function delete($uid) public function delete($uid)
{ {
if (!$this->enabled) { if (!$this->is_enabled()) {
return false; return false;
} }
@ -239,6 +249,10 @@ class kolab_storage_config
*/ */
public function find_folder($object = array()) public function find_folder($object = array())
{ {
if (!$this->is_enabled()) {
return;
}
// find folder object // find folder object
if ($object['_mailbox']) { if ($object['_mailbox']) {
foreach ($this->folders as $folder) { foreach ($this->folders as $folder) {
@ -967,7 +981,7 @@ class kolab_storage_config
/** /**
* Resolve the email message reference from the given URI * Resolve the email message reference from the given URI
*/ */
public function get_message_reference($uri, $rel = null) public static function get_message_reference($uri, $rel = null)
{ {
if ($linkref = self::parse_member_url($uri)) { if ($linkref = self::parse_member_url($uri)) {
$linkref['subject'] = $linkref['params']['subject']; $linkref['subject'] = $linkref['params']['subject'];