Changeset:
        d7da8202a300
        
https://sourceforge.net/p/mrbs/hg-code/ci/d7da8202a30051eb758404392600ebb363afe028
Author:
        Campbell Morrison <[email protected]>
Date:
        Thu Nov 05 07:53:31 2015 +0000
Log message:

Cached resiults in authGetUserLevel() in order to improve performance.  See SF 
Bugs #335.

diffstat:

 web/auth/auth_ldap.inc |  57 ++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 42 insertions(+), 15 deletions(-)

diffs (89 lines):

diff -r 31ed162e3fc3 -r d7da8202a300 web/auth/auth_ldap.inc
--- a/web/auth/auth_ldap.inc    Wed Nov 04 10:41:15 2015 +0000
+++ b/web/auth/auth_ldap.inc    Thu Nov 05 07:53:31 2015 +0000
@@ -515,43 +515,70 @@
  */
 function authGetUserLevel($user)
 {
-  global $auth;
   global $ldap_admin_group_dn;
-
-  $admins = $auth['admin'];
+  
+  // cache the user levels for performance
+  static $user_levels = array();
+  
   // User not logged in, user level '0'
   if (!isset($user))
   {
     return 0;
   }
   
+  if (isset($user_levels[$user]))
+  {
+    return $user_levels[$user];
+  }
+  
   if ($ldap_admin_group_dn)
   {
     $res = authLdapAction("authLdapCheckAdminGroupCallback", $user, $object);
     if ($res)
     {
-      return 2;
+      $level = 2;
     }
     else
     {
-      return 1;
+      $level = 1;
     }
   }
-    
-  // Check if the user is an admin
-  foreach ($admins as $admin)
+  elseif (authLdapIsAdmin($user))
   {
-    if (strcasecmp($user, $admin) == 0)
+    $level = 2;
+  }
+  else  // Everybody else is access level '1'
+  {
+    $level = 1;
+  }
+  
+  $user_levels[$user] = $level;
+  
+  return $user_levels[$user];
+}
+
+
+// Check if the user is an admin
+function authLdapIsAdmin($user)
+{
+  global $auth;
+  
+  if (isset($user) && ($user !== ''))
+  {
+    $admins = $auth['admin'];
+    foreach ($admins as $admin)
     {
-      return 2;
+      if (strcasecmp($user, $admin) == 0)
+      {
+        return TRUE;
+      }
     }
   }
-    
-  // Everybody else is access level '1'
-  return 1;
+  
+  return FALSE;
 }
-
-
+  
+  
 /* authLdapDebug($message)
  *
  * Output LDAP debugging, if the configuration variable

------------------------------------------------------------------------------
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to