From 0313d801085e7326a9d7f60133a5e7a25ef945cf Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sun, 7 Oct 2007 19:27:40 +0000 Subject: - Patch #181284 by killes and chx: performance improvements for user_access(). --- modules/user/user.module | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'modules') diff --git a/modules/user/user.module b/modules/user/user.module index 7c9a15ecb..fd18e2f5e 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -453,19 +453,16 @@ function user_access($string, $account = NULL) { // To reduce the number of SQL queries, we cache the user's permissions // in a static variable. if (!isset($perm[$account->uid])) { - $result = db_query("SELECT DISTINCT(p.perm) FROM {role} r INNER JOIN {permission} p ON p.rid = r.rid WHERE r.rid IN (". db_placeholders($account->roles) .")", array_keys($account->roles)); + $result = db_query("SELECT p.perm FROM {role} r INNER JOIN {permission} p ON p.rid = r.rid WHERE r.rid IN (". db_placeholders($account->roles) .")", array_keys($account->roles)); - $perm[$account->uid] = ''; + $perms = array(); while ($row = db_fetch_object($result)) { - $perm[$account->uid] .= "$row->perm, "; + $perms += array_flip(explode(', ', $row->perm)); } + $perm[$account->uid] = $perms; } - if (isset($perm[$account->uid])) { - return strpos($perm[$account->uid], "$string, ") !== FALSE; - } - - return FALSE; + return isset($perm[$account->uid][$string]); } /** -- cgit v1.2.3