Merge pull request #12006 from uberbrady/ldap_manager_cache
Added cache manager lookups in LDAP for performance boost
This commit is contained in:
commit
453f2c3b0e
1 changed files with 37 additions and 27 deletions
|
@ -175,6 +175,8 @@ class LdapSync extends Command
|
||||||
$tmp_pass = substr(str_shuffle('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), 0, 20);
|
$tmp_pass = substr(str_shuffle('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), 0, 20);
|
||||||
$pass = bcrypt($tmp_pass);
|
$pass = bcrypt($tmp_pass);
|
||||||
|
|
||||||
|
$manager_cache = [];
|
||||||
|
|
||||||
for ($i = 0; $i < $results['count']; $i++) {
|
for ($i = 0; $i < $results['count']; $i++) {
|
||||||
$item = [];
|
$item = [];
|
||||||
$item['username'] = isset($results[$i][$ldap_result_username][0]) ? $results[$i][$ldap_result_username][0] : '';
|
$item['username'] = isset($results[$i][$ldap_result_username][0]) ? $results[$i][$ldap_result_username][0] : '';
|
||||||
|
@ -217,6 +219,11 @@ class LdapSync extends Command
|
||||||
$user->department_id = $department->id;
|
$user->department_id = $department->id;
|
||||||
|
|
||||||
if($item['manager'] != null) {
|
if($item['manager'] != null) {
|
||||||
|
// Check Cache first
|
||||||
|
if (isset($manager_cache[$item['manager']])) {
|
||||||
|
// found in cache; use that and avoid extra lookups
|
||||||
|
$user->manager_id = $manager_cache[$item['manager']];
|
||||||
|
} else {
|
||||||
// Get the LDAP Manager
|
// Get the LDAP Manager
|
||||||
try {
|
try {
|
||||||
$ldap_manager = Ldap::findLdapUsers($item['manager'], -1, $this->option('filter'));
|
$ldap_manager = Ldap::findLdapUsers($item['manager'], -1, $this->option('filter'));
|
||||||
|
@ -246,6 +253,9 @@ class LdapSync extends Command
|
||||||
$user->manager_id = $ldap_manager->id;
|
$user->manager_id = $ldap_manager->id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$manager_cache[$item['manager']] = $ldap_manager && isset($ldap_manager->id) ? $ldap_manager->id : null; // Store results in cache, even if 'failed'
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sync activated state for Active Directory.
|
// Sync activated state for Active Directory.
|
||||||
|
|
Loading…
Add table
Reference in a new issue