Added package cache
authorMarcel Werk <burntime@woltlab.com>
Fri, 13 Jan 2012 14:53:46 +0000 (15:53 +0100)
committerMarcel Werk <burntime@woltlab.com>
Fri, 13 Jan 2012 14:53:46 +0000 (15:53 +0100)
wcfsetup/install/files/lib/data/package/PackageCache.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/WCF.class.php
wcfsetup/install/files/lib/system/benchmark/Benchmark.class.php

diff --git a/wcfsetup/install/files/lib/data/package/PackageCache.class.php b/wcfsetup/install/files/lib/data/package/PackageCache.class.php
new file mode 100644 (file)
index 0000000..3304a60
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+namespace wcf\data\package;
+use wcf\system\cache\CacheHandler;
+use wcf\system\SingletonFactory;
+
+/**
+ * Manages the package cache.
+ * 
+ * @author     Marcel Werk
+ * @copyright  2001-2012 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage data.package
+ * @category   Community Framework
+ */
+class PackageCache extends SingletonFactory {
+       /**
+        * list of cached packages
+        * @var array<wcf\data\package\Package>
+        */
+       protected $packages = array();
+       
+       /**
+        * @see wcf\system\SingletonFactory::init()
+        */
+       protected function init() {
+               CacheHandler::getInstance()->addResource('package', WCF_DIR.'cache/cache.package.php', 'wcf\system\cache\builder\PackageCacheBuilder');
+               $this->packages = CacheHandler::getInstance()->get('package');  
+       }
+       
+       /**
+        * Returns a specific package.
+        * 
+        * @param       integer         $packageID
+        * @return      wcf\data\package\Package
+        */
+       public function getPackage($packageID) {
+               if (isset($this->packages[$packageID])) return $this->packages[$packageID];
+               
+               return null;
+       }
+}
index da485e800f12048162bad3a9019ff898c475903b..fcee119ba5baab941698c271e340aa6b458471b4 100644 (file)
@@ -2,6 +2,7 @@
 namespace wcf\system;
 use wcf\data\application\Application;
 use wcf\data\package\Package;
+use wcf\data\package\PackageCache;
 use wcf\system\application\ApplicationHandler;
 use wcf\system\cache\CacheHandler;
 use wcf\system\database\statement\PreparedStatement;
@@ -393,36 +394,28 @@ class WCF {
        protected function initApplications() {
                if (PACKAGE_ID == 1) return;
                
-               // prepare statement
-               $sql = "SELECT  package, packageDir
-                       FROM    wcf".WCF_N."_package
-                       WHERE   packageID = ?";
-               $statement = WCF::getDB()->prepareStatement($sql);
-               
                // start main application
                $application = ApplicationHandler::getInstance()->getActiveApplication();
-               $this->loadApplication($statement, $application);
+               $this->loadApplication($application);
                
                // start dependent applications
                $applications = ApplicationHandler::getInstance()->getDependentApplications();
                foreach ($applications as $application) {
-                       $this->loadApplication($statement, $application, true);
+                       $this->loadApplication($application, true);
                }
        }
        
        /**
         * Loads an application.
         *
-        * @param       wcf\system\database\statement\PreparedStatement $statement
         * @param       wcf\data\application\Application                $application
         * @param       boolean                                         $isDependentApplication
         */     
-       protected function loadApplication(PreparedStatement $statement, Application $application, $isDepedentApplication = false) {
-               $statement->execute(array($application->packageID));
-               $row = $statement->fetchArray();
+       protected function loadApplication(Application $application, $isDepedentApplication = false) {
+               $package = PackageCache::getInstance()->getPackage($application->packageID);
                
                $abbreviation = ApplicationHandler::getInstance()->getAbbreviation($application->packageID);
-               $packageDir = util\FileUtil::getRealPath(WCF_DIR.$row['packageDir']);
+               $packageDir = util\FileUtil::getRealPath(WCF_DIR.$package->packageDir);
                self::$autoloadDirectories[$abbreviation] = $packageDir . 'lib/';
                
                $className = $abbreviation.'\system\\'.strtoupper($abbreviation).'Core';
@@ -433,7 +426,7 @@ class WCF {
                                require_once($configPath);
                        }
                        else {
-                               throw new exception\SystemException('Unable to load configuration for '.$row['package']);
+                               throw new exception\SystemException('Unable to load configuration for '.$package->package);
                        }
                        
                        // start application if not within ACP
@@ -443,7 +436,7 @@ class WCF {
                }
                else {
                        unset(self::$autoloadDirectories[$abbreviation]);
-                       throw new exception\SystemException('Unable to run '.$row['package'].', '.$className.' missing.');
+                       throw new exception\SystemException('Unable to run '.$row->package.', '.$className.' missing.');
                }
                
                // load application settings if not within ACP
index ab3a1981ebc17da1117416d0c0d1166b837fe684..2e9c701f33b530d5a4bd458c554caefb5a696bd2 100644 (file)
@@ -80,6 +80,8 @@ class Benchmark extends SingletonFactory {
                        $this->queryCount++;
                        $this->queryTime += $this->items[$index]['use'];
                }
+               
+               
        }
 
        /**