summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDries Buytaert2007-10-07 19:27:40 (GMT)
committerDries Buytaert2007-10-07 19:27:40 (GMT)
commit0313d801085e7326a9d7f60133a5e7a25ef945cf (patch)
treeeda1a4a78b728e13e35cfdee7c2702d452282d90
parentca8e9a1e181ed29ab33fbd7a5d665710869e9d23 (diff)
- Patch #181284 by killes and chx: performance improvements for user_access().
-rw-r--r--modules/user/user.module13
1 files changed, 5 insertions, 8 deletions
diff --git a/modules/user/user.module b/modules/user/user.module
index 7c9a15e..fd18e2f 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]);
}
/**