summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAri Selseng <ari@selseng.net>2019-03-01 23:52:58 +0100
committerBackportbot <backportbot-noreply@rullzer.com>2019-03-08 08:14:33 +0000
commit264b4ad3a911ba629e2a7551d64482aaaf707b99 (patch)
tree0e16aad414324e88ceb1980e84c0cfd06a74bb35 /lib
parent95bc1a0198bdd580679315cf144c8451c4056d57 (diff)
downloadnextcloud-server-264b4ad3a911ba629e2a7551d64482aaaf707b99.tar.gz
nextcloud-server-264b4ad3a911ba629e2a7551d64482aaaf707b99.zip
Avoid calculating folder size for parent that needs scan.
Signed-off-by: Ari Selseng <ari@selseng.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Files/Cache/Cache.php30
-rw-r--r--lib/private/Files/Cache/Scanner.php2
-rw-r--r--lib/private/Files/Cache/Wrapper/CacheJail.php4
-rw-r--r--lib/private/Files/Cache/Wrapper/CacheWrapper.php4
4 files changed, 32 insertions, 8 deletions
diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php
index 43e48e51654..5c7ef226096 100644
--- a/lib/private/Files/Cache/Cache.php
+++ b/lib/private/Files/Cache/Cache.php
@@ -3,6 +3,7 @@
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
* @author Andreas Fischer <bantu@owncloud.com>
+ * @author Ari Selseng <ari@selseng.net>
* @author Artem Kochnev <MrJeos@gmail.com>
* @author Björn Schießle <bjoern@schiessle.org>
* @author Florin Peter <github@florin-peter.de>
@@ -762,15 +763,38 @@ class Cache implements ICache {
* @param string|boolean $path
* @param array $data (optional) meta data of the folder
*/
- public function correctFolderSize($path, $data = null) {
+ public function correctFolderSize($path, $data = null, $isBackgroundScan = false) {
$this->calculateFolderSize($path, $data);
if ($path !== '') {
$parent = dirname($path);
if ($parent === '.' or $parent === '/') {
$parent = '';
}
- $this->correctFolderSize($parent);
+ if ($isBackgroundScan) {
+ $parentData = $this->get($parent);
+ if ($parentData['size'] !== -1 && $this->getIncompleteChildrenCount($parentData['fileid']) === 0) {
+ $this->correctFolderSize($parent, $parentData, $isBackgroundScan);
+ }
+ } else {
+ $this->correctFolderSize($parent);
+ }
+ }
+ }
+
+ /**
+ * get the incomplete count that shares parent $folder
+ *
+ * @param int $fileId the file id of the folder
+ * @return int
+ */
+ public function getIncompleteChildrenCount($fileId) {
+ if ($fileId > -1) {
+ $sql = 'SELECT count(*)
+ FROM `*PREFIX*filecache` WHERE `parent` = ? AND size = -1';
+ $result = $this->connection->executeQuery($sql, [$fileId]);
+ return (int)$result->fetchColumn();
}
+ return -1;
}
/**
@@ -907,4 +931,4 @@ class Cache implements ICache {
return trim(\OC_Util::normalizeUnicode($path), '/');
}
-}
+} \ No newline at end of file
diff --git a/lib/private/Files/Cache/Scanner.php b/lib/private/Files/Cache/Scanner.php
index ca9a0b794f9..e684b853103 100644
--- a/lib/private/Files/Cache/Scanner.php
+++ b/lib/private/Files/Cache/Scanner.php
@@ -532,7 +532,7 @@ class Scanner extends BasicEmitter implements IScanner {
$callback();
\OC_Hook::emit('Scanner', 'correctFolderSize', array('path' => $path));
if ($this->cacheActive && $this->cache instanceof Cache) {
- $this->cache->correctFolderSize($path);
+ $this->cache->correctFolderSize($path, null, true);
}
} catch (\OCP\Files\StorageInvalidException $e) {
// skip unavailable storages
diff --git a/lib/private/Files/Cache/Wrapper/CacheJail.php b/lib/private/Files/Cache/Wrapper/CacheJail.php
index 57f58e7d839..7e113d13678 100644
--- a/lib/private/Files/Cache/Wrapper/CacheJail.php
+++ b/lib/private/Files/Cache/Wrapper/CacheJail.php
@@ -265,9 +265,9 @@ class CacheJail extends CacheWrapper {
* @param string|boolean $path
* @param array $data (optional) meta data of the folder
*/
- public function correctFolderSize($path, $data = null) {
+ public function correctFolderSize($path, $data = null, $isBackgroundSize = false) {
if ($this->getCache() instanceof Cache) {
- $this->getCache()->correctFolderSize($this->getSourcePath($path), $data);
+ $this->getCache()->correctFolderSize($this->getSourcePath($path), $data, $isBackgroundSize);
}
}
diff --git a/lib/private/Files/Cache/Wrapper/CacheWrapper.php b/lib/private/Files/Cache/Wrapper/CacheWrapper.php
index da0a1b54e7f..223e678f323 100644
--- a/lib/private/Files/Cache/Wrapper/CacheWrapper.php
+++ b/lib/private/Files/Cache/Wrapper/CacheWrapper.php
@@ -258,9 +258,9 @@ class CacheWrapper extends Cache {
* @param string|boolean $path
* @param array $data (optional) meta data of the folder
*/
- public function correctFolderSize($path, $data = null) {
+ public function correctFolderSize($path, $data = null, $isBackgroundScan = false) {
if ($this->getCache() instanceof Cache) {
- $this->getCache()->correctFolderSize($path, $data);
+ $this->getCache()->correctFolderSize($path, $data, $isBackgroundScan);
}
}