From 95f3278e0eb567eac7bb40e270ee79be7b7867e0 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Fri, 3 Oct 2003 07:09:34 +0000 Subject: - Fixed small performance bug: when a user has no permissions, the query in user_access() was not cached. --- modules/user/user.module | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'modules/user/user.module') diff --git a/modules/user/user.module b/modules/user/user.module index d3bd79d35..6d7a97f80 100644 --- a/modules/user/user.module +++ b/modules/user/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); -- cgit v1.2.3