From e1e7b6a9406d8f9512f37e44d396be12dc1d02df Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 27 Jul 2013 11:36:27 +0200 Subject: Cache: don't check if the parent exists in the cache if we are already sure it does --- lib/files/cache/scanner.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib/files/cache') diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php index bcd6032fcac..d8e58f624a1 100644 --- a/lib/files/cache/scanner.php +++ b/lib/files/cache/scanner.php @@ -75,9 +75,10 @@ class Scanner extends BasicEmitter { * * @param string $file * @param int $reuseExisting + * @param bool $parentExists * @return array with metadata of the scanned file */ - public function scanFile($file, $reuseExisting = 0) { + public function scanFile($file, $reuseExisting = 0, $parentExists = false) { if (!self::isPartialFile($file) and !Filesystem::isFileBlacklisted($file) ) { @@ -85,7 +86,7 @@ class Scanner extends BasicEmitter { \OC_Hook::emit('\OC\Files\Cache\Scanner', 'scan_file', array('path' => $file, 'storage' => $this->storageId)); $data = $this->getData($file); if ($data) { - if ($file) { + if ($file and !$parentExists) { $parent = dirname($file); if ($parent === '.' or $parent === '/') { $parent = ''; @@ -162,7 +163,7 @@ class Scanner extends BasicEmitter { $child = ($path) ? $path . '/' . $file : $file; if (!Filesystem::isIgnoredDir($file)) { $newChildren[] = $file; - $data = $this->scanFile($child, $reuse); + $data = $this->scanFile($child, $reuse, true); if ($data) { if ($data['size'] === -1) { if ($recursive === self::SCAN_RECURSIVE) { -- cgit v1.2.3 From c8e60900fc75de39fbdf4dc6880f2e1cd61654ec Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sun, 28 Jul 2013 15:32:48 -0400 Subject: Move check so the variable will never be undefined --- lib/files/cache/scanner.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/files/cache') diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php index bcd6032fcac..520b41fe104 100644 --- a/lib/files/cache/scanner.php +++ b/lib/files/cache/scanner.php @@ -108,9 +108,9 @@ class Scanner extends BasicEmitter { // Only update metadata that has changed $newData = array_diff($data, $cacheData); } - } - if (!empty($newData)) { - $this->cache->put($file, $newData); + if (!empty($newData)) { + $this->cache->put($file, $newData); + } } return $data; } -- cgit v1.2.3 From dd4e33fe6b1cf9feccaeae33c81fc8b08fb24d4d Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sun, 28 Jul 2013 16:14:49 -0400 Subject: Fix calculating size for empty folders --- lib/files/cache/cache.php | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) (limited to 'lib/files/cache') diff --git a/lib/files/cache/cache.php b/lib/files/cache/cache.php index 3818fdbd840..458df56141c 100644 --- a/lib/files/cache/cache.php +++ b/lib/files/cache/cache.php @@ -485,27 +485,24 @@ class Cache { * @return int */ public function calculateFolderSize($path) { - $id = $this->getId($path); - if ($id === -1) { - return 0; - } - $sql = 'SELECT `size` FROM `*PREFIX*filecache` WHERE `parent` = ? AND `storage` = ?'; - $result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId())); $totalSize = 0; - $hasChilds = 0; - while ($row = $result->fetchRow()) { - $hasChilds = true; - $size = (int)$row['size']; - if ($size === -1) { - $totalSize = -1; - break; - } else { - $totalSize += $size; + $entry = $this->get($path); + if ($entry && $entry['mimetype'] === 'httpd/unix-directory') { + $id = $entry['fileid']; + $sql = 'SELECT `size` FROM `*PREFIX*filecache` WHERE `parent` = ? AND `storage` = ?'; + $result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId())); + while ($row = $result->fetchRow()) { + $size = (int)$row['size']; + if ($size === -1) { + $totalSize = -1; + break; + } else { + $totalSize += $size; + } + } + if ($entry['size'] !== $totalSize) { + $this->update($id, array('size' => $totalSize)); } - } - - if ($hasChilds) { - $this->update($id, array('size' => $totalSize)); } return $totalSize; } -- cgit v1.2.3 From 1faac6108c0c51d28021eb0676db9ad2b94a6f3d Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Mon, 29 Jul 2013 10:22:44 -0400 Subject: Use query to calculate folder size --- lib/files/cache/cache.php | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'lib/files/cache') diff --git a/lib/files/cache/cache.php b/lib/files/cache/cache.php index 458df56141c..c3d11ab4cfe 100644 --- a/lib/files/cache/cache.php +++ b/lib/files/cache/cache.php @@ -489,19 +489,22 @@ class Cache { $entry = $this->get($path); if ($entry && $entry['mimetype'] === 'httpd/unix-directory') { $id = $entry['fileid']; - $sql = 'SELECT `size` FROM `*PREFIX*filecache` WHERE `parent` = ? AND `storage` = ?'; + $sql = 'SELECT SUM(`size`), MIN(`size`) FROM `*PREFIX*filecache` '. + 'WHERE `parent` = ? AND `storage` = ?'; $result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId())); - while ($row = $result->fetchRow()) { - $size = (int)$row['size']; - if ($size === -1) { - $totalSize = -1; - break; + if ($row = $result->fetchRow()) { + list($sum, $min) = array_values($row); + $sum = (int)$sum; + $min = (int)$min; + if ($min === -1) { + $totalSize = $min; } else { - $totalSize += $size; + $totalSize = $sum; } - } - if ($entry['size'] !== $totalSize) { - $this->update($id, array('size' => $totalSize)); + if ($entry['size'] !== $totalSize) { + $this->update($id, array('size' => $totalSize)); + } + } } return $totalSize; -- cgit v1.2.3 From e2d3225e5aff343bf62b6dbb62eb3526e525cb6b Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Mon, 29 Jul 2013 18:24:05 +0200 Subject: implement a platform independent version of basename --- lib/files/cache/cache.php | 2 +- lib/util.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'lib/files/cache') diff --git a/lib/files/cache/cache.php b/lib/files/cache/cache.php index 3818fdbd840..5b8dc46b771 100644 --- a/lib/files/cache/cache.php +++ b/lib/files/cache/cache.php @@ -200,7 +200,7 @@ class Cache { $data['path'] = $file; $data['parent'] = $this->getParentId($file); - $data['name'] = basename($file); + $data['name'] = \OC_Util::basename($file); $data['encrypted'] = isset($data['encrypted']) ? ((int)$data['encrypted']) : 0; list($queryParts, $params) = $this->buildParts($data); diff --git a/lib/util.php b/lib/util.php index 981b05b2b46..004470908d1 100755 --- a/lib/util.php +++ b/lib/util.php @@ -892,4 +892,10 @@ class OC_Util { return $value; } + + public static function basename($file) + { + $t = explode('/', $file); + return array_pop($t); + } } -- cgit v1.2.3 From 74c54587ec1d816b41e5fbfca6f8d61f334a280c Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 29 Jul 2013 18:27:19 +0200 Subject: better variable naming --- lib/files/cache/scanner.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/files/cache') diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php index d8e58f624a1..53dc45e047c 100644 --- a/lib/files/cache/scanner.php +++ b/lib/files/cache/scanner.php @@ -75,10 +75,10 @@ class Scanner extends BasicEmitter { * * @param string $file * @param int $reuseExisting - * @param bool $parentExists + * @param bool $parentExistsInCache * @return array with metadata of the scanned file */ - public function scanFile($file, $reuseExisting = 0, $parentExists = false) { + public function scanFile($file, $reuseExisting = 0, $parentExistsInCache = false) { if (!self::isPartialFile($file) and !Filesystem::isFileBlacklisted($file) ) { @@ -86,7 +86,7 @@ class Scanner extends BasicEmitter { \OC_Hook::emit('\OC\Files\Cache\Scanner', 'scan_file', array('path' => $file, 'storage' => $this->storageId)); $data = $this->getData($file); if ($data) { - if ($file and !$parentExists) { + if ($file and !$parentExistsInCache) { $parent = dirname($file); if ($parent === '.' or $parent === '/') { $parent = ''; -- cgit v1.2.3 From 464afb5ecac95124c55b6a8af38410732a76275c Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Mon, 5 Aug 2013 13:51:45 +0200 Subject: use isset to prevent undefined index --- lib/files/cache/scanner.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/files/cache') diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php index dd212d84cc5..adecc2bb901 100644 --- a/lib/files/cache/scanner.php +++ b/lib/files/cache/scanner.php @@ -98,7 +98,7 @@ class Scanner extends BasicEmitter { $newData = $data; if ($reuseExisting and $cacheData = $this->cache->get($file)) { // only reuse data if the file hasn't explicitly changed - if ($data['mtime'] === $cacheData['mtime']) { + if (isset($data['mtime']) && isset($cacheData['mtime']) && $data['mtime'] === $cacheData['mtime']) { if (($reuseExisting & self::REUSE_SIZE) && ($data['size'] === -1)) { $data['size'] = $cacheData['size']; } -- cgit v1.2.3 From f22719b1eed9a66dc8978bc81b4bf9778834ca4d Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 12 Aug 2013 15:37:39 +0200 Subject: Scanner: correctly pass trough reuse options when doing a recursive scan --- lib/files/cache/scanner.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/files/cache') diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php index adecc2bb901..597eabecf54 100644 --- a/lib/files/cache/scanner.php +++ b/lib/files/cache/scanner.php @@ -184,7 +184,7 @@ class Scanner extends BasicEmitter { } \OC_DB::commit(); foreach ($childQueue as $child) { - $childSize = $this->scanChildren($child, self::SCAN_RECURSIVE); + $childSize = $this->scanChildren($child, self::SCAN_RECURSIVE, $reuse); if ($childSize === -1) { $size = -1; } else { -- cgit v1.2.3