Skip to content

Commit

Permalink
Avoid calculating folder size for parent that also needs proper scan.
Browse files Browse the repository at this point in the history
Signed-off-by: Ari Selseng <ari@selseng.net>
  • Loading branch information
ariselseng committed Mar 5, 2019
1 parent 679afa2 commit e5272e3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
30 changes: 27 additions & 3 deletions lib/private/Files/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -774,15 +775,38 @@ public function searchByTag($tag, $userId) {
* @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) {
$parent_data = $this->get($parent);
if ($parent_data['size'] !== -1 && $this->getIncompleteChildrenCount($parent_data['fileid']) === 0) {
$this->correctFolderSize($parent, $parent_data, $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;
}

/**
Expand Down Expand Up @@ -919,4 +943,4 @@ public function normalize($path) {

return trim(\OC_Util::normalizeUnicode($path), '/');
}
}
}
2 changes: 1 addition & 1 deletion lib/private/Files/Cache/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ private function runBackgroundScanJob(callable $callback, $path) {
$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
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Files/Cache/Wrapper/CacheWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ public function searchByTag($tag, $userId) {
* @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);
}
}

Expand Down

0 comments on commit e5272e3

Please sign in to comment.