From abeed19efd1b5774a521ea3cdaf48a2a5b0ca6c3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Sat, 20 Apr 2013 23:19:23 +0200 Subject: [PATCH] Update CacheListPage Closes #1209 --- .../lib/acp/page/CacheListPage.class.php | 75 +++++-------------- .../cache/source/ApcCacheSource.class.php | 2 +- 2 files changed, 19 insertions(+), 58 deletions(-) diff --git a/wcfsetup/install/files/lib/acp/page/CacheListPage.class.php b/wcfsetup/install/files/lib/acp/page/CacheListPage.class.php index e1ccddbf96..769552ed87 100755 --- a/wcfsetup/install/files/lib/acp/page/CacheListPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/CacheListPage.class.php @@ -7,6 +7,7 @@ use wcf\system\Regex; use wcf\system\WCF; use wcf\util\DirectoryUtil; use wcf\util\FileUtil; +use wcf\util\StringUtil; /** * Shows a list of all cache resources. @@ -75,82 +76,42 @@ class CacheListPage extends AbstractPage { // set version $this->cacheData['version'] = WCF_VERSION; - // get package dirs - $sql = "SELECT packageDir - FROM wcf".WCF_N."_package - WHERE isApplication = ?"; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(array(1)); - while ($row = $statement->fetchArray()) { - $packageDir = FileUtil::getRealPath(WCF_DIR.$row['packageDir']); - $this->readCacheFiles('data', $packageDir.'cache'); - } + $this->readCacheFiles('data', WCF_DIR.'cache'); break; case 'wcf\system\cache\source\MemcachedCacheSource': // set version $this->cacheData['version'] = WCF_VERSION; - - // get package dirs - $sql = "SELECT packageDir - FROM wcf".WCF_N."_package - WHERE isApplication = ?"; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(array(1)); - while ($row = $statement->fetchArray()) { - $packageDir = FileUtil::getRealPath(WCF_DIR.$row['packageDir']); - $this->readCacheFiles('data', $packageDir.'cache'); - } break; case 'wcf\system\cache\source\ApcCacheSource': // set version $this->cacheData['version'] = phpversion('apc'); - // get package dirs - $sql = "SELECT packageDir, packageName - FROM wcf".WCF_N."_package - WHERE isApplication = ?"; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(array(1)); - - $packageNames = array(); - while ($row = $statement->fetchArray()) { - $packagePath = FileUtil::getRealPath(WCF_DIR.$row['packageDir']).'cache/'; - $packageNames[$packagePath] = $row['packageName']; - } - $apcinfo = apc_cache_info('user'); $cacheList = $apcinfo['cache_list']; + usort($cacheList, function ($a, $b) { + return $a['info'] > $b['info']; + }); + + $prefix = new Regex('^WCF_'.substr(sha1(WCF_DIR), 0, 10) . '_'); foreach ($cacheList as $cache) { - $cachePath = FileUtil::addTrailingSlash(FileUtil::unifyDirSeperator(dirname($cache['info']))); - if (isset($packageNames[$cachePath])) { - // Use the packageName + the instance number, because pathes could confuse the administrator. - // He could think this is a file cache. If instanceName would be unique, we could use it instead. - $packageName = $packageNames[$cachePath]; - if (!isset($this->caches['data'])) { - $this->caches['data'] = array(); - } - if (!isset($this->caches['data'][$packageName])) { - $this->caches['data'][$packageName] = array(); - } - - // get additional cache information - $this->caches['data'][$packageName][] = array( - 'filename' => basename($cache['info'], '.php'), - 'filesize' => $cache['mem_size'], - 'mtime' => $cache['mtime'], - ); - - $this->cacheData['files']++; - $this->cacheData['size'] += $cache['mem_size']; - } + if (!$prefix->match($cache['info'])) continue; + + // get additional cache information + $this->caches['data']['apc'][] = array( + 'filename' => $prefix->replace($cache['info'], ''), + 'filesize' => $cache['mem_size'], + 'mtime' => $cache['mtime'] + ); + + $this->cacheData['files']++; + $this->cacheData['size'] += $cache['mem_size']; } break; case 'wcf\system\cache\source\NoCacheSource': $this->cacheData['version'] = WCF_VERSION; - $this->cacheData['files'] = $this->cacheData['size'] = 0; break; } diff --git a/wcfsetup/install/files/lib/system/cache/source/ApcCacheSource.class.php b/wcfsetup/install/files/lib/system/cache/source/ApcCacheSource.class.php index eb207b6210..aa936ed56a 100644 --- a/wcfsetup/install/files/lib/system/cache/source/ApcCacheSource.class.php +++ b/wcfsetup/install/files/lib/system/cache/source/ApcCacheSource.class.php @@ -30,7 +30,7 @@ class ApcCacheSource implements ICacheSource { } // set variable prefix to prevent collision - $this->prefix = substr(sha1(WCF_DIR), 0, 8) . '_'; + $this->prefix = 'WCF_'.substr(sha1(WCF_DIR), 0, 10) . '_'; } /** -- 2.20.1