MDL-57193 auth_db: Flip the array outside the loop for better perf

Also as the recent changes where affecting the whitespaces quite
a lot, I took the liberty of aligning a few lines which weren't.
This commit is contained in:
Frederic Massart 2016-12-02 16:02:00 +08:00
parent ec3e79134f
commit 7fc7486f49
No known key found for this signature in database
GPG Key ID: AC343CE142B12FB9

View File

@ -302,15 +302,18 @@ class auth_plugin_db extends auth_plugin_base {
// Find obsolete users.
if (count($userlist)) {
$removeusers = array();
$params['authtype'] = $this->authtype;
$sql = "SELECT u.id, u.username
FROM {user} u
WHERE u.auth=:authtype AND u.deleted=0 AND u.mnethostid=:mnethostid $suspendselect";
$params['mnethostid'] = $CFG->mnet_localhost_id;
$internalusersrs = $DB->get_recordset_sql($sql, $params);
$params['authtype'] = $this->authtype;
$sql = "SELECT u.id, u.username
FROM {user} u
WHERE u.auth=:authtype
AND u.deleted=0
AND u.mnethostid=:mnethostid
$suspendselect";
$params['mnethostid'] = $CFG->mnet_localhost_id;
$internalusersrs = $DB->get_recordset_sql($sql, $params);
$usernamelist = array_flip($userlist);
foreach ($internalusersrs as $internaluser) {
// Arrange the associative array.
$usernamelist = array_flip($userlist);
if (!array_key_exists($internaluser->username, $usernamelist)) {
$removeusers[] = $internaluser;
}