]> git.mxchange.org Git - mailer.git/commitdiff
Speed up of isAdmin()
authorRoland Häder <roland@mxchange.org>
Sun, 4 Nov 2012 00:11:24 +0000 (00:11 +0000)
committerRoland Häder <roland@mxchange.org>
Sun, 4 Nov 2012 00:11:24 +0000 (00:11 +0000)
inc/mysql-manager.php
inc/session-functions.php

index 8d59df8a9fb59edf9b3d77c04c8ecb59e49079b2..a7ecf50e8dd9596fd862cc2a0c37d06e06f918ba 100644 (file)
@@ -562,8 +562,15 @@ function fetchUserData ($value, $column = 'userid') {
  * login.
  */
 function isAdmin () {
+       // Is there cache?
+       if (isset($GLOBALS[__FUNCTION__])) {
+               // Return it
+               return $GLOBALS[__FUNCTION__];
+       } // END - if
+
        // No admin in installation phase!
        if ((isInstallationPhase()) || (!isAdminRegistered())) {
+               $GLOBALS[__FUNCTION__] = FALSE;
                return FALSE;
        } // END - if
 
@@ -588,44 +595,43 @@ function isAdmin () {
                //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Current adminId is zero. isSessionVariableSet(admin_id)=' . intval(isSessionVariableSet('admin_id')) . ',isSessionVariableSet(admin_md5)=' . intval(isSessionVariableSet('admin_md5')));
 
                // Abort here now
+               $GLOBALS[__FUNCTION__] = FALSE;
                return FALSE;
        } // END - if
 
-       // Is there cache?
-       if (!isset($GLOBALS[__FUNCTION__][$adminId])) {
-               // Init it with failed
-               $GLOBALS[__FUNCTION__][$adminId] = FALSE;
-
-               // Search in array for entry
-               if (isset($GLOBALS['admin_hash'])) {
-                       // Use cached string
-                       $valPass = $GLOBALS['admin_hash'];
-               } elseif ((!empty($passwordFromCookie)) && (isAdminHashSet($adminId) === TRUE) && (!empty($adminId))) {
-                       // Login data is valid or not?
-                       $valPass = encodeHashForCookie(getAdminHash($adminId));
-
-                       // Cache it away
-                       $GLOBALS['admin_hash'] = $valPass;
-
-                       // Count cache hits
-                       incrementStatsEntry('cache_hits');
-               } elseif ((!empty($adminId)) && ((!isExtensionActive('cache')) || (isAdminHashSet($adminId) === FALSE))) {
-                       // Get admin hash and hash it
-                       $valPass = encodeHashForCookie(getAdminHash($adminId));
-
-                       // Cache it away
-                       $GLOBALS['admin_hash'] = $valPass;
-               }
+       // Init it with failed
+       $GLOBALS[__FUNCTION__] = FALSE;
 
-               if (!empty($valPass)) {
-                       // Check if password is valid
-                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '(' . $valPass . '==' . $passwordFromCookie . ')='.intval($valPass == $passwordFromCookie));
-                       $GLOBALS[__FUNCTION__][$adminId] = ($GLOBALS['admin_hash'] == $passwordFromCookie);
-               } // END - if
+       // Search in array for entry
+       if (isset($GLOBALS['admin_hash'])) {
+               // Use cached string
+               $valPass = $GLOBALS['admin_hash'];
+       } elseif ((!empty($passwordFromCookie)) && (isAdminHashSet($adminId) === TRUE) && (!empty($adminId))) {
+               // Login data is valid or not?
+               $valPass = encodeHashForCookie(getAdminHash($adminId));
+
+               // Cache it away
+               $GLOBALS['admin_hash'] = $valPass;
+
+               // Count cache hits
+               incrementStatsEntry('cache_hits');
+       } elseif ((!empty($adminId)) && ((!isExtensionActive('cache')) || (isAdminHashSet($adminId) === FALSE))) {
+               // Get admin hash and hash it
+               $valPass = encodeHashForCookie(getAdminHash($adminId));
+
+               // Cache it away
+               $GLOBALS['admin_hash'] = $valPass;
+       }
+
+       // $valPass shall not be empty. If so, the admin has not found.
+       if (!empty($valPass)) {
+               // Check if password is valid
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '(' . $valPass . '==' . $passwordFromCookie . ')='.intval($valPass == $passwordFromCookie));
+               $GLOBALS[__FUNCTION__] = ($GLOBALS['admin_hash'] == $passwordFromCookie);
        } // END - if
 
        // Return result of comparision
-       return $GLOBALS[__FUNCTION__][$adminId];
+       return $GLOBALS[__FUNCTION__];
 }
 
 // Generates a list of "max receiveable emails per day"
index 384e3f465ec1a2d7df2195b81b1f31b524c6f28d..7601911fc83cda7d869817202f844b493098a9eb 100644 (file)
@@ -135,6 +135,9 @@ function destroyAdminSession ($destroy = TRUE) {
        setAdminMd5('');
        setAdminLast('');
 
+       // Set cache to FALSE
+       $GLOBALS['isAdmin'] = FALSE;
+
        // Destroy session if requested and return status
        if ($destroy === TRUE) {
                return session_destroy();