Commit 0313d801 authored by Dries's avatar Dries

- Patch #181284 by killes and chx: performance improvements for user_access().

parent ca8e9a1e
......@@ -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]);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment