From: hickert Date: Tue, 15 Sep 2009 12:23:05 +0000 (+0000) Subject: Updated gen_uids - much faster for big ldap trees now. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=066388c74595496a5ff5bc2b91d7e6152634726c;p=gosa.git Updated gen_uids - much faster for big ldap trees now. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14251 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-core/include/functions.inc b/gosa-core/include/functions.inc index d02d7d462..4962bb11f 100644 --- a/gosa-core/include/functions.inc +++ b/gosa-core/include/functions.inc @@ -1730,15 +1730,15 @@ function gen_uids($rule, $attributes) /* Recurse through all possible combinations */ $proposed= recurse($stripped, $variables); - /* Get list of used ID's */ - $used= array(); - $ldap= $config->get_ldap_link(); - $ldap->cd($config->current['BASE']); - $ldap->search('(uid=*)'); - - while($attrs= $ldap->fetch()){ - $used[]= $attrs['uid'][0]; - } +# /* Get list of used ID's */ +# $used= array(); + $ldap= $config->get_ldap_link(); + $ldap->cd($config->current['BASE']); +# $ldap->search('(uid=*)'); +# +# while($attrs= $ldap->fetch()){ +# $used[]= $attrs['uid'][0]; +# } /* Remove used uids and watch out for id tags */ $ret= array(); @@ -1751,7 +1751,9 @@ function gen_uids($rule, $attributes) for ($i= 0, $p= pow(10,$size); $i < $p; $i++){ $number= sprintf("%0".$size."d", $i); $res= preg_replace('/{id:(\d+)}/', $number, $uid); - if (!in_array($res, $used)){ + + $ldap->search("uid={$res}",array('dn')); + if(!count($ldap)){ $uid= $res; break; } @@ -1765,7 +1767,8 @@ function gen_uids($rule, $attributes) mt_srand((double) microtime()*1000000); $number= sprintf("%0".$size."d", mt_rand(0, pow(10, $size)-1)); $res= preg_replace('/{id#(\d+)}/', $number, $uid); - if (!in_array($res, $used)){ + $ldap->search("uid={$res}",array('dn')); + if(!count($ldap)){ $uid= $res; break; } @@ -1773,7 +1776,8 @@ function gen_uids($rule, $attributes) } /* Don't assign used ones */ - if (!in_array($uid, $used)){ + $ldap->search("uid={$uid}",array('dn')); + if(!count($ldap)){ /* Add uid, but remove {} first. These are invalid anyway. */ $ret[]= preg_replace('/[{}]/', '', $uid); }