Skip to content

Commit

Permalink
MDL-57193 auth_db: Flip the array outside the loop for better perf
Browse files Browse the repository at this point in the history
Also as the recent changes where affecting the whitespaces quite
a lot, I took the liberty of aligning a few lines which weren't.
  • Loading branch information
Frederic Massart committed Dec 2, 2016
1 parent a43c2ab commit 8432dbe
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions auth/db/auth.php
Expand Up @@ -303,15 +303,18 @@ function sync_users(progress_trace $trace, $do_updates=false) {
// 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;
}
Expand Down

0 comments on commit 8432dbe

Please sign in to comment.