Changeset 26286


Ignore:
Timestamp:
06/06/10 14:13:58 (7 years ago)
Author:
flack
Message:

we don't need to cache merged privilegesets by both int and boolean values, boolean is enough

refs #1848

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ragnaroek/midcom/midcom.core/midcom/services/auth.php

    r26285 r26286  
    394394     * @access private
    395395     */
    396     var $_privileges_cache = Array();
     396    private static $_privileges_cache = Array();
    397397
    398398    /**
     
    914914        elseif (is_string($for_user))
    915915        {
    916             $cache_key = "{$for_user}-{$object_guid}";
     916            $cache_key = "{$for_user}::{$object_guid}";
    917917        }
    918918        else
    919919        {
    920             $cache_key = "{$for_user->id}-{$object_guid}";
    921         }
    922 
    923         $privilege_key = "{$cache_key}-{$privilege}";
    924 
    925         // Cache results of ACL checks per session
    926         static $cached_privileges = array();
    927 
    928         if (!isset($cached_privileges[$privilege_key]))
     920            $cache_key = "{$for_user->id}::{$object_guid}";
     921        }
     922
     923        if (!isset(self::$_privileges_cache[$cache_key]))
    929924        {
    930925            //debug_push_class(__CLASS__, __FUNCTION__);
     
    932927            //debug_pop();
    933928
    934             $full_privileges = $this->get_privileges_byguid($object_guid, $object_class, $for_user);
    935             foreach ($full_privileges as $priv => $value)
    936             {
    937                 $cached_privileges["{$cache_key}-{$priv}"] = ($value == MIDCOM_PRIVILEGE_ALLOW);
    938             }
    939 
    940             if (! array_key_exists($privilege, $full_privileges))
    941             {
    942                 debug_push_class(__CLASS__, __FUNCTION__);
    943                 debug_add("The privilege {$privilege} is unknown at this point. Assuming not granted privilege.", MIDCOM_LOG_WARN);
    944                 debug_pop();
    945                 return false;
    946             }
    947         }
    948 
    949         return $cached_privileges[$privilege_key];
     929            $this->_load_privileges_byguid($object_guid, $object_class, $for_user);
     930        }
     931
     932        if (!array_key_exists($privilege, self::$_privileges_cache[$cache_key]))
     933        {
     934            debug_push_class(__CLASS__, __FUNCTION__);
     935            debug_add("The privilege {$privilege} is unknown at this point. Assuming not granted privilege.", MIDCOM_LOG_WARN);
     936            debug_pop();
     937            return false;
     938        }
     939
     940        return self::$_privileges_cache[$cache_key][$privilege];
    950941    }
    951942
     
    11391130    function get_privileges(&$content_object, $user = null)
    11401131    {
    1141         return $this->get_privileges_byguid($content_object->guid, get_class($content_object), $user);
     1132        return $this->_get_privileges_byguid($content_object->guid, get_class($content_object), $user);
    11421133    }
    11431134
     
    11541145     * @param midcom_core_user $user The user against which to check the privilege, defaults to the currently authenticated user.
    11551146     *     You may specify "EVERYONE" instead of an object to check what an anonymous user can do.
    1156      * @return Array Associative listing of all privileges and their value.
    1157      */
    1158     function get_privileges_byguid($object_guid, $object_class, $user = null)
     1147     */
     1148    private function _load_privileges_byguid($object_guid, $object_class, $user = null)
    11591149    {
    11601150        /* No idea if there should be some special log message written */
     
    12171207        $cache_id = "{$cache_user_id}::{$object_guid}";
    12181208
    1219         if (array_key_exists($cache_id, $this->_privileges_cache))
    1220         {
    1221             return $this->_privileges_cache[$cache_id];
    1222         }
     1209        if (array_key_exists($cache_id, self::$_privileges_cache))
     1210        {
     1211            return;
     1212        }
     1213
     1214        self::$_privileges_cache[$cache_id] = array();
    12231215
    12241216        //debug_push_class(__CLASS__, __FUNCTION__);
     
    12421234                debug_add('Failed to convert an object, falling back to an empty privilege set for the object in question. See debug level log for details.');
    12431235                debug_pop();
    1244                 return Array();
     1236                return;
    12451237            }
    12461238        }
     
    12671259        }
    12681260
    1269         // dafault magic class privileges user
     1261        // default magic class privileges user
    12701262        $dmcp_user = is_null($this->user) ? 'ANONYMOUS' : 'USERS';
    12711263
     
    12811273
    12821274        // cache for future queries
    1283         $this->_privileges_cache[$cache_id] = $full_privileges;
    1284 
    1285         return $full_privileges;
     1275        foreach ($full_privileges as $priv => $value)
     1276        {
     1277            $full_privileges[$priv] = ($value == MIDCOM_PRIVILEGE_ALLOW);
     1278        }
     1279        self::$_privileges_cache[$cache_id] = $full_privileges;
    12861280    }
    12871281
Note: See TracChangeset for help on using the changeset viewer.