summaryrefslogtreecommitdiff
path: root/modules/user.module
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2003-10-03 07:09:34 +0000
committerDries Buytaert <dries@buytaert.net>2003-10-03 07:09:34 +0000
commit95f3278e0eb567eac7bb40e270ee79be7b7867e0 (patch)
tree1020294eed30a1618b16fd58692f9ef197b84ae6 /modules/user.module
parentd646fb073df46ec15af1c2357114e3dfc3e93ed0 (diff)
downloadbrdo-95f3278e0eb567eac7bb40e270ee79be7b7867e0.tar.gz
brdo-95f3278e0eb567eac7bb40e270ee79be7b7867e0.tar.bz2
- Fixed small performance bug: when a user has no permissions, the query
in user_access() was not cached.
Diffstat (limited to 'modules/user.module')
-rw-r--r--modules/user.module11
1 files changed, 10 insertions, 1 deletions
diff --git a/modules/user.module b/modules/user.module
index d3bd79d35..6d7a97f80 100644
--- a/modules/user.module
+++ b/modules/user.module
@@ -263,7 +263,9 @@ function user_access($string) {
global $user;
static $perm;
+ static $cache;
+ // User #1 has all priveleges:
if ($user->uid == 1) {
return 1;
}
@@ -273,13 +275,20 @@ function user_access($string) {
** in a static variable.
*/
- if (!$perm) {
+ if (!$cache) {
if ($user->uid) {
$perm = db_result(db_query("SELECT p.perm FROM {role} r, {permission} p WHERE r.rid = p.rid AND name = '%s'", $user->role), 0);
}
else {
$perm = db_result(db_query("SELECT p.perm FROM {role} r, {permission} p WHERE r.rid = p.rid AND name = 'anonymous user'"), 0);
}
+
+ /*
+ ** We use a separate $cache variable because $perm might be empty when a
+ ** user has no access rights.
+ */
+
+ $cache = 1;
}
return strstr($perm, $string);