From acd574b65015afea76df6ab30ab802a3e09c1f72 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Mon, 17 Dec 2012 19:03:47 +0100 Subject: [PATCH] Small performance fix - cache identities list in-memory --- .../kolab_delegation_engine.php | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/plugins/kolab_delegation/kolab_delegation_engine.php b/plugins/kolab_delegation/kolab_delegation_engine.php index aefaeeb0..1d3505c9 100644 --- a/plugins/kolab_delegation/kolab_delegation_engine.php +++ b/plugins/kolab_delegation/kolab_delegation_engine.php @@ -515,6 +515,21 @@ class kolab_delegation_engine return $parsed ? $this->parse_ldap_record($this->cache['user']) : $this->cache['user']; } + /** + * Returns current user identities + * + * @return array List of identities + */ + public function user_identities() + { + // cache result in-memory, we need it more than once + if ($this->identities === null) { + $this->identities = $this->rc->user->list_identities(); + } + + return $this->identities; + } + /** * Update LDAP record of current user * @@ -559,7 +574,7 @@ class kolab_delegation_engine $other_ns = $storage->get_namespace('other'); $folders = $storage->list_folders(); $use_subs = $this->rc->config->get('kolab_use_subscriptions'); - $identities = $this->rc->user->list_identities(); + $identities = $this->user_identities(); $emails = array(); $uids = array(); @@ -693,7 +708,7 @@ class kolab_delegation_engine return; } - $identities = $this->rc->user->list_identities(); + $identities = $this->user_identities(); $emails = $_SESSION['delegators'][$context]; foreach ($identities as $ident) { @@ -723,10 +738,10 @@ class kolab_delegation_engine } // return only user addresses (exclude all delegators addresses) else if (!empty($_SESSION['delegators'])) { - $identities = $this->rc->user->list_identities(); + $identities = $this->user_identities(); $emails[] = $this->rc->user->get_username(); - foreach ($this->rc->user->list_identities() as $identity) { + foreach ($identities as $identity) { $emails[] = $identity['email']; }