Update CacheListPage
authorTim Düsterhus <duesterhus@woltlab.com>
Sat, 20 Apr 2013 21:19:23 +0000 (23:19 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Sat, 20 Apr 2013 21:19:23 +0000 (23:19 +0200)
Closes #1209

wcfsetup/install/files/lib/acp/page/CacheListPage.class.php
wcfsetup/install/files/lib/system/cache/source/ApcCacheSource.class.php

index e1ccddbf96c1881230115acf927c499e9dc6db56..769552ed879074bb2160d9c4c7cf5972066dcc2a 100755 (executable)
@@ -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;
                }
                
index eb207b621089087af88a5d4283ccd77c66ff9e4c..aa936ed56af0da940b4239fceebac33fd1c70d01 100644 (file)
@@ -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) . '_';
        }
        
        /**