Removing the usage counter in from the template system
authorRobert Sesek <rsesek@bluestatic.org>
Thu, 16 Aug 2007 20:51:48 +0000 (20:51 +0000)
committerRobert Sesek <rsesek@bluestatic.org>
Thu, 16 Aug 2007 20:51:48 +0000 (20:51 +0000)
* Template.php:
(BSTemplate::cache): No longer initialize the usage counter
(BSTemplate::fetch): Only increment the BSTemplate->uncached[] template counter when the template is not cached
(BSTemplate::flsuh): Remove the template debug block and only show uncached templates and their usage

Template.php

index 70d8f5a2e9939b90c75e423d5a79ff95fa6e673e..8400c1afc7e280179846d77b720a60c1413b8efa 100644 (file)
@@ -82,12 +82,6 @@ class BSTemplate
        */
        protected $cache = array();
        
-       /**
-       * A list of the number of times each template has been used
-       * @var  array
-       */
-       protected $usage = array();
-       
        /**
        * A list of templates that weren't cached, but are still used
        * @var  array
@@ -203,8 +197,7 @@ class BSTemplate
                                        $template = $this->_parseTemplate($this->_loadTemplate($name));
                                }
                                
-                               $this->cache["$name"] = $template;
-                               $this->usage["$name"] = 0;
+                               $this->cache[$name] = $template;
                        }
                }
        }
@@ -220,25 +213,18 @@ class BSTemplate
        */
        public function fetch($name)
        {
-               if (isset($this->cache["$name"]))
+               if (isset($this->cache[$name]))
                {
-                       $template = $this->cache["$name"];
+                       $template = $this->cache[$name];
                }
                else
                {
-                       $this->uncached[] = $name;
+                       $this->uncached[$name]++;
                        BSApp::Debug("Manually loading template '$name'");
                        $template = $this->_loadTemplate($name);
                        $template = $this->_parseTemplate($template);
                }
                
-               if (!isset($this->usage["$name"]))
-               {
-                       $this->usage["$name"] = 0;
-               }
-               
-               $this->usage["$name"]++;
-               
                return $template;
        }
        
@@ -268,28 +254,14 @@ class BSTemplate
                        $debugBlock .= "\n<div align=\"center\">Executed in " . round(BSFunctions::FetchMicrotimeDiff($_SERVER['REQUEST_TIME']), 10) . ' seconds</div>';                        
                        $debugBlock .= "\n<br /><div align=\"center\">" . BSApp::GetDebugList() . "</div>";
                        
-                       $optlist = array();
-                       $usage = array();
-                       foreach ($this->usage AS $name => $count)
+                       if (sizeof($this->uncached) > 0)
                        {
-                               if (in_array($name, $this->uncached))
+                               foreach ($this->uncached AS $name => $count)
                                {
-                                       $optlist[] = $name . '[' . $count . ']';
+                                       $tpls[] = $name . "($count)";
                                }
-                               $usage[] = $name . " ($count)";
-                       }
-                       $sizeof = sizeof($this->uncached);
-                       if ($sizeof > 0)
-                       {
-                               $debugBlock .= "<br /><div style=\"color: red\" align=\"center\"><strong>Uncached Template(s):</strong> $sizeof ( " . implode(' &nbsp; ', $optlist) . " )</div>\n";
-                       }
-                       
-                       $debugBlock .= (sizeof($this->uncached) < 1 ? "<br />\n" : '') . "<div align=\"center\"><select><option>Template Usage (" . array_sum($this->usage) . ")</option>";
-                       foreach ($usage AS $tpl)
-                       {
-                               $debugBlock .= "<option>--- $tpl</option>";
+                               $debugBlock .= "<br /><div style=\"color: red\" align=\"center\"><strong>Uncached Templates:</strong>" . implode(', ', $tpls) . " )</div>\n";
                        }
-                       $debugBlock .= "</select></div>\n";
                        
                        if (BSApp::GetType('Db'))
                        {