Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit f3f8f7a

Browse files
committed
Perf issues with massive ldap directories: divide listing time by 2
1 parent 0a3c1f2 commit f3f8f7a

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

core/src/core/classes/class.AuthService.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
*/
2828
class AuthService
2929
{
30+
public static $cacheRoles = false;
3031
public static $roles;
3132
public static $useSession = true;
3233
private static $currentUser;
@@ -623,7 +624,8 @@ public static function updateDefaultRights(&$userObject)
623624
{
624625
if (!$userObject->hasParent()) {
625626
$changes = false;
626-
foreach (ConfService::getRepositoriesList() as $repositoryId => $repoObject) {
627+
$repoList = ConfService::getRepositoriesList();
628+
foreach ($repoList as $repositoryId => $repoObject) {
627629
if(!self::allowedForCurrentGroup($repoObject, $userObject)) continue;
628630
if($repoObject->isTemplate) continue;
629631
if ($repoObject->getDefaultRight() != "") {
@@ -634,7 +636,8 @@ public static function updateDefaultRights(&$userObject)
634636
if ($changes) {
635637
$userObject->recomputeMergedRole();
636638
}
637-
foreach (self::getRolesList(array(), true) as $roleId => $roleObject) {
639+
$rolesList = self::getRolesList(array(), true);
640+
foreach ($rolesList as $roleId => $roleObject) {
638641
if(!self::allowedForCurrentGroup($roleObject, $userObject)) continue;
639642
if ($userObject->getProfile() == "shared" && $roleObject->autoAppliesTo("shared")) {
640643
$userObject->addRole($roleObject);
@@ -651,7 +654,8 @@ public static function updateDefaultRights(&$userObject)
651654
*/
652655
public static function updateAutoApplyRole(&$userObject)
653656
{
654-
foreach (self::getRolesList(array(), true) as $roleId => $roleObject) {
657+
$roles = self::getRolesList(array(), true);
658+
foreach ($roles as $roleObject) {
655659
if(!self::allowedForCurrentGroup($roleObject, $userObject)) continue;
656660
if ($roleObject->autoAppliesTo($userObject->getProfile()) || $roleObject->autoAppliesTo("all")) {
657661
$userObject->addRole($roleObject);
@@ -990,6 +994,8 @@ public static function listUsers($baseGroup = "/", $regexp = null, $offset = -1,
990994
call_user_func($countCallback, $index, count($users), "Update users");
991995
}
992996

997+
self::$cacheRoles = true;
998+
self::$roles = null;
993999
foreach (array_keys($users) as $userId) {
9941000
if(($userId == "guest" && !ConfService::getCoreConf("ALLOW_GUEST_BROWSING", "auth")) || $userId == "ajxp.admin.users" || $userId == "") continue;
9951001
if($regexp != null && !$authDriver->supportsUsersPagination() && !preg_match("/$regexp/i", $userId)) continue;
@@ -1008,6 +1014,8 @@ public static function listUsers($baseGroup = "/", $regexp = null, $offset = -1,
10081014
}
10091015
}
10101016
}
1017+
self::$cacheRoles = false;
1018+
10111019
if ($paginated && $cleanLosts) {
10121020
// Remove 'lost' items (children without parents).
10131021
foreach ($allUsers as $id => $object) {
@@ -1224,20 +1232,25 @@ public static function limitedRoleFromParent($parentUser)
12241232
*/
12251233
public static function getRolesList($roleIds = array(), $excludeReserved = false)
12261234
{
1227-
//if(isSet(self::$roles)) return self::$roles;
1235+
if(self::$cacheRoles && !count($roleIds) && $excludeReserved == true && self::$roles != null) {
1236+
return self::$roles;
1237+
}
12281238
$confDriver = ConfService::getConfStorageImpl();
1229-
self::$roles = $confDriver->listRoles($roleIds, $excludeReserved);
1239+
$roles = $confDriver->listRoles($roleIds, $excludeReserved);
12301240
$repoList = null;
1231-
foreach (self::$roles as $roleId => $roleObject) {
1241+
foreach ($roles as $roleId => $roleObject) {
12321242
if (is_a($roleObject, "AjxpRole")) {
12331243
if($repoList == null) $repoList = ConfService::getRepositoriesList("all");
12341244
$newRole = new AJXP_Role($roleId);
12351245
$newRole->migrateDeprectated($repoList, $roleObject);
1236-
self::$roles[$roleId] = $newRole;
1246+
$roles[$roleId] = $newRole;
12371247
self::updateRole($newRole);
12381248
}
12391249
}
1240-
return self::$roles;
1250+
if(self::$cacheRoles && !count($roleIds) && $excludeReserved == true) {
1251+
self::$roles = $roles;
1252+
}
1253+
return $roles;
12411254
}
12421255

12431256
/**

core/src/plugins/auth.multi/class.multiAuthDriver.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,18 @@ public function supportsUsersPagination()
221221
public function listUsersPaginated($baseGroup, $regexp, $offset, $limit, $recursive = true)
222222
{
223223
if (!empty($this->baseName) && $regexp == null) {
224-
return $this->drivers[$this->baseName]->listUsersPaginated($baseGroup, $regexp, $offset, $limit, $recursive);
224+
$users = $this->drivers[$this->baseName]->listUsersPaginated($baseGroup, $regexp, $offset, $limit, $recursive);
225+
$this->addToCache(array_keys($users), $this->baseName);
226+
return $users;
225227
} else {
226228
$keys = array_keys($this->drivers);
227-
return $this->drivers[$keys[0]]->listUsersPaginated($baseGroup, $regexp, $offset, $limit, $recursive) + $this->drivers[$keys[1]]->listUsersPaginated($baseGroup, $regexp, $offset, $limit, $recursive);
229+
$k0 = $keys[0];
230+
$k1 = $keys[1];
231+
$users0 = $this->drivers[$k0]->listUsersPaginated($baseGroup, $regexp, $offset, $limit, $recursive);
232+
$users1 = $this->drivers[$k1]->listUsersPaginated($baseGroup, $regexp, $offset, $limit, $recursive);
233+
$this->addToCache(array_keys($users0), $k0);
234+
$this->addToCache(array_keys($users1), $k1);
235+
return $users0 + $users1;
228236
}
229237
}
230238

core/src/plugins/conf.sql/class.AJXP_SqlUser.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,9 @@ public function storageExists()
121121
// already loaded!
122122
return true;
123123
}
124-
$this->load();
125-
if (! isSet($this->rights["ajxp.admin"])) {
124+
$result_rights = dibi::query('SELECT [rights] FROM [ajxp_user_rights] WHERE [login] = %s AND [repo_uuid] = %s', $this->getId(), 'ajxp.admin');
125+
$testRight = $result_rights->fetchSingle();
126+
if ($testRight === false) {
126127
return false;
127128
}
128129

0 commit comments

Comments
 (0)