From fe5264217df4e956ee26f29f56bcfd2b55e8db22 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Fri, 2 Dec 2016 16:02:00 +0800 Subject: [PATCH] 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. --- auth/db/auth.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/auth/db/auth.php b/auth/db/auth.php index 1473437bdb6..03e8eafd57a 100644 --- a/auth/db/auth.php +++ b/auth/db/auth.php @@ -303,15 +303,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; }