Some more speed hacks
authorRoland Häder <roland@mxchange.org>
Wed, 10 Mar 2010 01:30:50 +0000 (01:30 +0000)
committerRoland Häder <roland@mxchange.org>
Wed, 10 Mar 2010 01:30:50 +0000 (01:30 +0000)
inc/wrapper-functions.php

index 4a07785f7d8b9128c38affbd70bcc1f0109de9cd..881b7c94e647e020406017684da90dcd372d67f9 100644 (file)
@@ -706,17 +706,14 @@ function setUsername ($userName) {
 
 // Get username
 function getUsername () {
-       // default is guest
-       $username = getMessage('USERNAME_GUEST');
-
        // User name set?
-       if (isset($GLOBALS['username'])) {
-               // Use the set name
-               $username = $GLOBALS['username'];
+       if (!isset($GLOBALS['username'])) {
+               // No, so it has to be a guest
+               $GLOBALS['username'] = getMessage('USERNAME_GUEST');
        } // END - if
 
        // Return it
-       return $username;
+       return $GLOBALS['username'];
 }
 
 // Wrapper function for installation phase
@@ -815,8 +812,14 @@ function isUserDataValid () {
        // User id should not be zero so abort here
        if (!isCurrentUserIdSet()) return false;
 
-       // Is the array there and filled?
-       return ((isset($GLOBALS['user_data'][getCurrentUserId()])) && (count($GLOBALS['user_data'][getCurrentUserId()]) > 1));
+       // Is it cached?
+       if (!isset($GLOBALS['is_userdata_valid'][getCurrentUserId()])) {
+               // Determine it
+               $GLOBALS['is_userdata_valid'][getCurrentUserId()] = ((isset($GLOBALS['user_data'][getCurrentUserId()])) && (count($GLOBALS['user_data'][getCurrentUserId()]) > 1));
+       } // END - if
+
+       // Return the result
+       return $GLOBALS['is_userdata_valid'][getCurrentUserId()];
 }
 
 // Setter for current userid
@@ -848,17 +851,23 @@ function isDebuggingTemplateCache () {
 
 // Wrapper for fetchUserData() and getUserData() calls
 function getFetchedUserData ($keyColumn, $userId, $valueColumn) {
-       // Default is 'guest'
-       $data = getMessage('USERNAME_GUEST');
-
-       // Can we fetch the user data?
-       if (($userId > 0) && (fetchUserData($userId, $keyColumn))) {
-               // Now get the data back
-               $data = getUserData($valueColumn);
+       // Is it cached?
+       if (!isset($GLOBALS['user_data_cache'][$userid][$keyColumn][$valueColumn])) {
+               // Default is 'guest'
+               $data = getMessage('USERNAME_GUEST');
+
+               // Can we fetch the user data?
+               if (($userId > 0) && (fetchUserData($userId, $keyColumn))) {
+                       // Now get the data back
+                       $data = getUserData($valueColumn);
+               } // END - if
+
+               // Cache it
+               $GLOBALS['user_data_cache'][$userid][$keyColumn][$valueColumn] = $data;
        } // END - if
 
        // Return it
-       return $data;
+       return $GLOBALS['user_data_cache'][$userid][$keyColumn][$valueColumn];
 }
 
 // Wrapper for strpos() to ease porting from deprecated ereg() function