summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAleksander Machniak <machniak@kolabsys.com>2019-06-24 09:59:51 +0000
committerAleksander Machniak <machniak@kolabsys.com>2019-06-24 09:59:51 +0000
commit89b1896ae72f242c4a58a6977eb11abf5f571648 (patch)
tree4beedbfd2221e5a8736de98d308780779d8098a7 /lib
parent4dd0a08ffb79e1f10a578245fe596104c3efe3cb (diff)
downloadwebadmin-89b1896ae72f242c4a58a6977eb11abf5f571648.tar.gz
Fix performance when validating multiple email addresses (Bifrost#T221026)
Cache domains list in memory, so it's reused without searching in ldap for every validated email address again and again.
Diffstat (limited to 'lib')
-rw-r--r--lib/api/kolab_api_service_form_value.php46
1 files changed, 26 insertions, 20 deletions
diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index a8fbd2a..58799f6 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -1604,28 +1604,34 @@ class kolab_api_service_form_value extends kolab_api_service
*/
private function _get_valid_domains($my_primary_domain = null)
{
- $my_primary_domain = $my_primary_domain !== null
- ? $my_primary_domain
- : $_SESSION['user']->get_domain();
-
- $auth = Auth::get_instance();
- $conf = Conf::get_instance();
- $all_domains = $auth->list_domains(array(), array(), array('page_size' => 99999));
- $all_domains = $all_domains['list'];
- $all_basedns = Array();
- $dna = $conf->get('domain_name_attribute');
- $dra = $conf->get('domain_rootdn_attribute');
+ static $domains, $context;
+
+ $my_primary_domain = $my_primary_domain ?: $_SESSION['user']->get_domain();
+
+ if (is_array($domains) && $context === $my_primary_domain) {
+ Log::trace("_get_valid_domains(" . $my_primary_domain . "), use memory cache");
+ return $domains;
+ }
Log::trace("_get_valid_domains(" . $my_primary_domain . ")");
- $valid_domains = $my_primary_domain ? array($my_primary_domain) : array();
+ $auth = Auth::get_instance();
+ $conf = Conf::get_instance();
+ $all_domains = $auth->list_domains(array(), array(), array('page_size' => 99999));
+ $all_domains = $all_domains['list'];
+ $all_basedns = array();
+ $dna = $conf->get('domain_name_attribute');
+ $dra = $conf->get('domain_rootdn_attribute');
+ $domains = $my_primary_domain ? array($my_primary_domain) : array();
+ $context = $my_primary_domain;
+
foreach ($all_domains as $domain_id => $domain_attrs) {
if (!is_array($domain_attrs[$dna])) {
- $domain_attrs[$dna] = (array)($domain_attrs[$dna]);
+ $domain_attrs[$dna] = (array) $domain_attrs[$dna];
}
if (in_array($my_primary_domain, $domain_attrs[$dna])) {
- $valid_domains = array_merge($valid_domains, $domain_attrs[$dna]);
+ $domains = array_merge($domains, $domain_attrs[$dna]);
}
if (array_key_exists($dra, $domain_attrs)) {
@@ -1637,17 +1643,17 @@ class kolab_api_service_form_value extends kolab_api_service
}
}
- foreach ($all_basedns as $base_dn => $domains) {
- if (in_array($my_primary_domain, $domains)) {
- $valid_domains = array_merge($valid_domains, $domains);
+ foreach ($all_basedns as $base_dn => $_domains) {
+ if (in_array($my_primary_domain, $_domains)) {
+ $domains = array_merge($domains, $_domains);
}
}
- $result = array_unique($valid_domains);
+ $domains = array_unique($domains);
- Log::trace("_get_valid_domains result: " . var_export($result, TRUE));
+ Log::trace("_get_valid_domains result: " . var_export($domains, true));
- return array_unique($result);
+ return $domains;
}
private function _validate_email_address_in_any_of_my_domains($mail_address)