diff options
author | Dries Buytaert <dries@buytaert.net> | 2007-10-07 19:27:40 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2007-10-07 19:27:40 +0000 |
commit | 0313d801085e7326a9d7f60133a5e7a25ef945cf (patch) | |
tree | eda1a4a78b728e13e35cfdee7c2702d452282d90 | |
parent | ca8e9a1e181ed29ab33fbd7a5d665710869e9d23 (diff) | |
download | brdo-0313d801085e7326a9d7f60133a5e7a25ef945cf.tar.gz brdo-0313d801085e7326a9d7f60133a5e7a25ef945cf.tar.bz2 |
- Patch #181284 by killes and chx: performance improvements for user_access().
-rw-r--r-- | modules/user/user.module | 13 |
1 files changed, 5 insertions, 8 deletions
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]); } /** |