Changeset 26399


Ignore:
Timestamp:
06/20/10 10:34:16 (7 years ago)
Author:
flack
Message:

use statuc node cache to reduce overhead for dynamic_loads, refs #359

Location:
branches/developers/flack/acltuning/midcom.core/midcom
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/developers/flack/acltuning/midcom.core/midcom/application.php

    r26071 r26399  
    14141414     * NAP interface can be accessed through this function. A reference is returned.
    14151415     *
    1416      * This function maintains one NAP Class per concept. Usually this is enough,
     1416     * This function maintains one NAP Class per context. Usually this is enough,
    14171417     * since you mostly will access it in context 0, the default. The problem is, that
    14181418     * this is not 100% efficient: If you instantiate two different NAP Classes in
  • branches/developers/flack/acltuning/midcom.core/midcom/helper/_basicnav.php

    r26398 r26399  
    1313 *
    1414 * It is responsible for collecting the available
    15  * Information and for building the navigational Tree out of it. This
     15 * information and for building the navigational tree out of it. This
    1616 * class is only the internal interface to the NAP System and is used by
    1717 * midcom_helper_nav as a node cache. The framework should ensure that
     
    2121 * by the NAP classes of the components. You can retrieve a node/leaf tree
    2222 * of the content, and for each element you can retrieve a URL name and a
    23  * long name for Navigation display.
     23 * long name for navigation display.
    2424 *
    25  * Leaves and Nodes are both indexed by Integer constants which are assigned
     25 * Leaves and Nodes are both indexed by integer constants which are assigned
    2626 * by the framework. The framework defines two starting points in this tree:
    2727 * The root node and the "current" node. The current node defined through
     
    4040 * keys required by the component:
    4141 *
    42  * - MIDCOM_NAV_NAME => The Real (= displayable) name of the element
     42 * - MIDCOM_NAV_NAME => The real (= displayable) name of the element
    4343 *
    4444 * Other keys delivered to NAP users include:
     
    115115     * @var Array
    116116     */
    117     private $_nodes;
     117    private static $_nodes;
    118118
    119119    /**
     
    206206        $this->_leaves = array();
    207207
    208         $this->_nodes = array();
    209208        $this->_loader = $_MIDCOM->get_component_loader();
    210209
     
    236235                    {
    237236                        // Reset the Root node's URL Parameter to an empty string.
    238                         $this->_nodes[$this->_root][MIDCOM_NAV_URL] = '';
     237                        self::$_nodes[$this->_root][MIDCOM_NAV_URL] = '';
    239238                        $root_set = true;
    240239                    }
     
    451450        else
    452451        {
    453             if (!$up || (!isset($this->_nodes[$up]) && $this->_loadNode($up) !== MIDCOM_ERROK))
     452            if (!$up || (!isset(self::$_nodes[$up]) && $this->_loadNode($up) !== MIDCOM_ERROK))
    454453            {
    455454                $up = $urltopic->up;
     
    458457
    459458            if (   !$nodedata[MIDCOM_NAV_NODEID]
    460                 || !array_key_exists($nodedata[MIDCOM_NAV_NODEID], $this->_nodes))
     459                || !array_key_exists($nodedata[MIDCOM_NAV_NODEID], self::$_nodes))
    461460            {
    462461                return null;
    463462            }
    464             if (!array_key_exists(MIDCOM_NAV_RELATIVEURL, $this->_nodes[$nodedata[MIDCOM_NAV_NODEID]]))
     463            if (!array_key_exists(MIDCOM_NAV_RELATIVEURL, self::$_nodes[$nodedata[MIDCOM_NAV_NODEID]]))
    465464            {
    466465                return null;
    467466            }
    468467
    469             $nodedata[MIDCOM_NAV_RELATIVEURL] = $this->_nodes[$nodedata[MIDCOM_NAV_NODEID]][MIDCOM_NAV_RELATIVEURL] . $nodedata[MIDCOM_NAV_URL];
     468            $nodedata[MIDCOM_NAV_RELATIVEURL] = self::$_nodes[$nodedata[MIDCOM_NAV_NODEID]][MIDCOM_NAV_RELATIVEURL] . $nodedata[MIDCOM_NAV_URL];
    470469        }
    471470
     
    863862        // Load the node data and check visibility.
    864863        $nodedata = $this->_get_node($topic, $up);
    865 
     864       
    866865        if (! $this->_is_object_visible($nodedata))
    867866        {
     
    869868        }
    870869        // The node is visible, add it to the list.
    871         $this->_nodes[$nodedata[MIDCOM_NAV_ID]] = $nodedata;
    872         $this->_guid_map[$nodedata[MIDCOM_NAV_GUID]] =& $this->_nodes[$nodedata[MIDCOM_NAV_ID]];
     870        self::$_nodes[$nodedata[MIDCOM_NAV_ID]] = $nodedata;
     871        $this->_guid_map[$nodedata[MIDCOM_NAV_GUID]] =& self::$_nodes[$nodedata[MIDCOM_NAV_ID]];
    873872
    874873        // Load the current leaf, this does *not* load the leaves from the DB, this is done
     
    954953
    955954            // Check if we have a cached version of the node already
    956             if (isset($this->_nodes[$node_id]))
     955            if (isset(self::$_nodes[$node_id]))
    957956            {
    958957                return MIDCOM_ERROK;
     
    962961        {
    963962            // Check if we have a cached version of the node already
    964             if (isset($this->_nodes[$node_id]))
     963            if (isset(self::$_nodes[$node_id]))
    965964            {
    966965                return MIDCOM_ERROK;
     
    10101009               && $parent->guid
    10111010               && $parent->up != 0
    1012                && !isset($this->_nodes[$parent->id]))
     1011               && !isset(self::$_nodes[$parent->id]))
    10131012        {
    10141013            $parent = $parent->get_parent();
     
    10361035        foreach ($uplinks as $uptopic)
    10371036        {
    1038             if (array_key_exists($uptopic->id, $this->_nodes))
     1037            if (array_key_exists($uptopic->id, self::$_nodes))
    10391038            {
    10401039                // We already saw this node, no point in loading it again
     
    11321131        $up = null;
    11331132
    1134         if (!isset($this->_nodes[$parent_node]))
     1133        if (!isset(self::$_nodes[$parent_node]))
    11351134        {
    11361135            if ($this->_loadNode($parent_node) != MIDCOM_ERROK)
     
    11481147        }
    11491148
    1150         //echo "Called for {$parent_node} {$this->_nodes[$parent_node][MIDCOM_NAV_RELATIVEURL]}<br />\n";
     1149        //echo "Called for {$parent_node} {self::$_nodes[$parent_node][MIDCOM_NAV_RELATIVEURL]}<br />\n";
    11511150
    11521151        // Use the midgard_query_builder to get the subnodes
    1153         $mc = midcom_db_topic::new_collector('up', $this->_nodes[$parent_node][MIDCOM_NAV_OBJECT]->id);
     1152        $mc = midcom_db_topic::new_collector('up', self::$_nodes[$parent_node][MIDCOM_NAV_OBJECT]->id);
    11541153        $mc->add_constraint('name', '<>', '');
    11551154
     
    11781177        $node = (int) $parent_node;
    11791178
    1180         if ($up || $node != $this->_nodes[$parent_node][MIDCOM_NAV_OBJECT]->id)
     1179        if ($up || $node != self::$_nodes[$parent_node][MIDCOM_NAV_OBJECT]->id)
    11811180        {
    11821181            $up = $this->_nodeid($node, $up);
     
    11881187            $subnode = midcom_db_topic::get_cached($guid);
    11891188            $subnode_id = $this->_nodeid($subnode->id, $up);
    1190             if (   !isset($this->_nodes[$subnode_id])
     1189            if (   !isset(self::$_nodes[$subnode_id])
    11911190                && $this->_loadNode($subnode, $up) !== MIDCOM_ERROK)
    11921191            {
     
    12141213            foreach ($result as $subnode_id)
    12151214            {
    1216                 $sortable_result[] = $this->_nodes[$subnode_id];
     1215                $sortable_result[] = self::$_nodes[$subnode_id];
    12171216            }
    12181217
     
    12511250        static $listed = array();
    12521251
    1253         if (!array_key_exists($parent_node, $this->_nodes))
     1252        if (!array_key_exists($parent_node, self::$_nodes))
    12541253        {
    12551254            if ($this->_loadNode($parent_node) != MIDCOM_ERROK)
     
    12611260        if (!in_array($parent_node, $this->_loaded_leaves, true))
    12621261        {
    1263             $this->_load_leaves($this->_nodes[$parent_node]);
     1262            $this->_load_leaves(self::$_nodes[$parent_node]);
    12641263        }
    12651264
     
    13251324        }
    13261325
    1327         if (!isset($this->_nodes[$node_id]))
     1326        if (!isset(self::$_nodes[$node_id]))
    13281327        {
    13291328            if ($this->_loadNode($node) != MIDCOM_ERROK)
     
    13321331            }
    13331332
    1334             if (!isset($this->_nodes[$node_id]))
     1333            if (!isset(self::$_nodes[$node_id]))
    13351334            {
    13361335                return false;
     
    13381337        }
    13391338
    1340         return $this->_nodes[$node_id];
     1339        return self::$_nodes[$node_id];
    13411340    }
    13421341
     
    13651364        $node_id = $id_elements[0];
    13661365
    1367         if (   !isset($this->_nodes[$node_id])
     1366        if (   !isset(self::$_nodes[$node_id])
    13681367            && $this->_loadNode($node_id) != MIDCOM_ERROK)
    13691368        {
     
    13731372        }
    13741373
    1375         $this->_load_leaves($this->_nodes[$node_id]);
     1374        $this->_load_leaves(self::$_nodes[$node_id]);
    13761375
    13771376        return (array_key_exists($leaf_id, $this->_leaves));
     
    14521451    function get_node_uplink($node_id)
    14531452    {
    1454         if (!array_key_exists($node_id, $this->_nodes))
     1453        if (!array_key_exists($node_id, self::$_nodes))
    14551454        {
    14561455            if ($this->_loadNode($node_id) != MIDCOM_ERROK)
     
    14601459        }
    14611460
    1462         return $this->_nodes[$node_id][MIDCOM_NAV_NODEID];
     1461        return self::$_nodes[$node_id][MIDCOM_NAV_NODEID];
    14631462    }
    14641463
Note: See TracChangeset for help on using the changeset viewer.