From 0c7b8679c93293b7fb417a00c457e4ed9ea38470 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Fri, 13 Jan 2012 15:53:46 +0100 Subject: [PATCH] Added package cache --- .../lib/data/package/PackageCache.class.php | 42 +++++++++++++++++++ .../install/files/lib/system/WCF.class.php | 23 ++++------ .../lib/system/benchmark/Benchmark.class.php | 2 + 3 files changed, 52 insertions(+), 15 deletions(-) create mode 100644 wcfsetup/install/files/lib/data/package/PackageCache.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 index 0000000000..3304a603fe --- /dev/null +++ b/wcfsetup/install/files/lib/data/package/PackageCache.class.php @@ -0,0 +1,42 @@ + + * @package com.woltlab.wcf + * @subpackage data.package + * @category Community Framework + */ +class PackageCache extends SingletonFactory { + /** + * list of cached packages + * @var array + */ + 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; + } +} diff --git a/wcfsetup/install/files/lib/system/WCF.class.php b/wcfsetup/install/files/lib/system/WCF.class.php index da485e800f..fcee119ba5 100644 --- a/wcfsetup/install/files/lib/system/WCF.class.php +++ b/wcfsetup/install/files/lib/system/WCF.class.php @@ -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 diff --git a/wcfsetup/install/files/lib/system/benchmark/Benchmark.class.php b/wcfsetup/install/files/lib/system/benchmark/Benchmark.class.php index ab3a1981eb..2e9c701f33 100644 --- a/wcfsetup/install/files/lib/system/benchmark/Benchmark.class.php +++ b/wcfsetup/install/files/lib/system/benchmark/Benchmark.class.php @@ -80,6 +80,8 @@ class Benchmark extends SingletonFactory { $this->queryCount++; $this->queryTime += $this->items[$index]['use']; } + + } /** -- 2.20.1