Allow re-using already known fileinfo when calculating folder sizes

This commit is contained in:
Robin Appelman 2014-02-28 14:23:07 +01:00
parent 8a93a2e7d5
commit da386aad59
5 changed files with 27 additions and 13 deletions

View File

@ -354,9 +354,10 @@ class Shared_Cache extends Cache {
* get the size of a folder and set it in the cache
*
* @param string $path
* @param array $entry (optional) meta data of the folder
* @return int
*/
public function calculateFolderSize($path) {
public function calculateFolderSize($path, $entry = null) {
if ($cache = $this->getSourceCache($path)) {
return $cache->calculateFolderSize($this->files[$path]);
}

View File

@ -498,9 +498,10 @@ class Cache {
* update the folder size and the size of all parent folders
*
* @param string|boolean $path
* @param array $data (optional) meta data of the folder
*/
public function correctFolderSize($path) {
$this->calculateFolderSize($path);
public function correctFolderSize($path, $data = null) {
$this->calculateFolderSize($path, $data);
if ($path !== '') {
$parent = dirname($path);
if ($parent === '.' or $parent === '/') {
@ -514,11 +515,14 @@ class Cache {
* get the size of a folder and set it in the cache
*
* @param string $path
* @param array $entry (optional) meta data of the folder
* @return int
*/
public function calculateFolderSize($path) {
public function calculateFolderSize($path, $entry = null) {
$totalSize = 0;
$entry = $this->get($path);
if (is_null($entry)) {
$entry = $this->get($path);
}
if ($entry && $entry['mimetype'] === 'httpd/unix-directory') {
$id = $entry['fileid'];
$sql = 'SELECT SUM(`size`) AS f1, MIN(`size`) AS f2, ' .

View File

@ -13,15 +13,21 @@ class HomeCache extends Cache {
* get the size of a folder and set it in the cache
*
* @param string $path
* @param array $entry (optional) meta data of the folder
* @return int
*/
public function calculateFolderSize($path) {
public function calculateFolderSize($path, $entry = null) {
if ($path !== '/' and $path !== '' and $path !== 'files') {
return parent::calculateFolderSize($path);
return parent::calculateFolderSize($path, $entry);
} elseif ($path === '' or $path === '/') {
// since the size of / isn't used (the size of /files is used instead) there is no use in calculating it
return 0;
}
$totalSize = 0;
$entry = $this->get($path);
if (is_null($entry)) {
$entry = $this->get($path);
}
if ($entry && $entry['mimetype'] === 'httpd/unix-directory') {
$id = $entry['fileid'];
$sql = 'SELECT SUM(`size`) FROM `*PREFIX*filecache` ' .
@ -40,6 +46,7 @@ class HomeCache extends Cache {
/**
* @param string $path
* @return array
*/
public function get($path) {
$data = parent::get($path);

View File

@ -173,14 +173,16 @@ class Scanner extends BasicEmitter {
* @param string $path
* @param bool $recursive
* @param int $reuse
* @return int the size of the scanned folder or -1 if the size is unknown at this stage
* @return array with the meta data of the scanned file or folder
*/
public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1) {
if ($reuse === -1) {
$reuse = ($recursive === self::SCAN_SHALLOW) ? self::REUSE_ETAG | self::REUSE_SIZE : 0;
}
$this->scanFile($path, $reuse);
return $this->scanChildren($path, $recursive, $reuse);
$data = $this->scanFile($path, $reuse);
$size = $this->scanChildren($path, $recursive, $reuse);
$data['size'] = $size;
return $data;
}
/**

View File

@ -38,8 +38,8 @@ class Updater {
if ($storage) {
$cache = $storage->getCache($internalPath);
$scanner = $storage->getScanner($internalPath);
$scanner->scan($internalPath, Scanner::SCAN_SHALLOW);
$cache->correctFolderSize($internalPath);
$data = $scanner->scan($internalPath, Scanner::SCAN_SHALLOW);
$cache->correctFolderSize($internalPath, $data);
self::correctFolder($path, $storage->filemtime($internalPath));
self::correctParentStorageMtime($storage, $internalPath);
}