diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-01-18 16:57:30 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-01-18 16:57:30 +0100 |
commit | 14c98b4df78a489cfdf4656cb66a79a13116ac17 (patch) | |
tree | ed48eff319ae53b2e94fca8e5ff518536b715068 | |
parent | a32f8aa87a959bf0050cbd7f710a690427f5a1f2 (diff) | |
parent | 30d6222e64e14d589f2ab8b8ef2ec015fc7e1bd5 (diff) | |
download | nextcloud-server-14c98b4df78a489cfdf4656cb66a79a13116ac17.tar.gz nextcloud-server-14c98b4df78a489cfdf4656cb66a79a13116ac17.zip |
Merge pull request #21519 from owncloud/propagate-folder-size
propagate folder size in the same query for write updates
-rw-r--r-- | apps/files_sharing/lib/scanner.php | 29 | ||||
-rw-r--r-- | apps/files_sharing/lib/sharedpropagator.php | 7 | ||||
-rw-r--r-- | apps/files_sharing/lib/sharedstorage.php | 2 | ||||
-rw-r--r-- | lib/private/files/cache/propagator.php | 12 | ||||
-rw-r--r-- | lib/private/files/cache/scanner.php | 1 | ||||
-rw-r--r-- | lib/private/files/cache/updater.php | 10 | ||||
-rw-r--r-- | tests/lib/cache/file.php | 4 |
7 files changed, 54 insertions, 11 deletions
diff --git a/apps/files_sharing/lib/scanner.php b/apps/files_sharing/lib/scanner.php index bd6a28a4934..e9cc40ae42c 100644 --- a/apps/files_sharing/lib/scanner.php +++ b/apps/files_sharing/lib/scanner.php @@ -22,10 +22,14 @@ namespace OC\Files\Cache; +use OC\Files\ObjectStore\NoopScanner; +use OC\Files\Storage\Shared; + /** * Scanner for SharedStorage */ class SharedScanner extends Scanner { + private $sourceScanner; /** * Returns metadata from the shared storage, but @@ -35,12 +39,35 @@ class SharedScanner extends Scanner { * * @return array an array of metadata of the file */ - protected function getData($path){ + public function getData($path) { $data = parent::getData($path); $sourcePath = $this->storage->getSourcePath($path); list($sourceStorage, $internalPath) = \OC\Files\Filesystem::resolvePath($sourcePath); $data['permissions'] = $sourceStorage->getPermissions($internalPath); return $data; } + + private function getSourceScanner() { + if ($this->sourceScanner) { + return $this->sourceScanner; + } + if ($this->storage->instanceOfStorage('\OC\Files\Storage\Shared')) { + /** @var \OC\Files\Storage\Storage $storage */ + list($storage) = $this->storage->resolvePath(''); + $this->sourceScanner = $storage->getScanner(); + return $this->sourceScanner; + } else { + return null; + } + } + + public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true) { + $sourceScanner = $this->getSourceScanner(); + if ($sourceScanner instanceof NoopScanner) { + return []; + } else { + return parent::scanFile($file, $reuseExisting, $parentId, $cacheData, $lock); + } + } } diff --git a/apps/files_sharing/lib/sharedpropagator.php b/apps/files_sharing/lib/sharedpropagator.php index fd3e14b28f8..29735934499 100644 --- a/apps/files_sharing/lib/sharedpropagator.php +++ b/apps/files_sharing/lib/sharedpropagator.php @@ -32,12 +32,13 @@ class SharedPropagator extends Propagator { /** * @param string $internalPath * @param int $time - * @return array[] all propagated entries + * @param int $sizeDifference + * @return \array[] all propagated entries */ - public function propagateChange($internalPath, $time) { + public function propagateChange($internalPath, $time, $sizeDifference = 0) { $source = $this->storage->getSourcePath($internalPath); /** @var \OC\Files\Storage\Storage $storage */ list($storage, $sourceInternalPath) = \OC\Files\Filesystem::resolvePath($source); - return $storage->getPropagator()->propagateChange($sourceInternalPath, $time); + return $storage->getPropagator()->propagateChange($sourceInternalPath, $time, $sizeDifference); } } diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php index 697856e1de5..542d0e9e48c 100644 --- a/apps/files_sharing/lib/sharedstorage.php +++ b/apps/files_sharing/lib/sharedstorage.php @@ -609,7 +609,7 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage { * @param string $path * @return array */ - private function resolvePath($path) { + public function resolvePath($path) { $source = $this->getSourcePath($path); return \OC\Files\Filesystem::resolvePath($source); } diff --git a/lib/private/files/cache/propagator.php b/lib/private/files/cache/propagator.php index 1e85a2ecc8b..50264e54d44 100644 --- a/lib/private/files/cache/propagator.php +++ b/lib/private/files/cache/propagator.php @@ -43,9 +43,10 @@ class Propagator implements IPropagator { /** * @param string $internalPath * @param int $time - * @return array[] all propagated cache entries + * @param int $sizeDifference number of bytes the file has grown + * @return array[] all propagated entries */ - public function propagateChange($internalPath, $time) { + public function propagateChange($internalPath, $time, $sizeDifference = 0) { $cache = $this->storage->getCache($internalPath); $parentId = $cache->getParentId($internalPath); @@ -58,7 +59,12 @@ class Propagator implements IPropagator { } $mtime = max($time, $entry['mtime']); - $cache->update($parentId, ['mtime' => $mtime, 'etag' => $this->storage->getETag($entry['path'])]); + if ($entry['size'] === -1) { + $newSize = -1; + } else { + $newSize = $entry['size'] + $sizeDifference; + } + $cache->update($parentId, ['mtime' => $mtime, 'etag' => $this->storage->getETag($entry['path']), 'size' => $newSize]); $parentId = $entry['parent']; } diff --git a/lib/private/files/cache/scanner.php b/lib/private/files/cache/scanner.php index 1c50978a2e5..60daa323b4b 100644 --- a/lib/private/files/cache/scanner.php +++ b/lib/private/files/cache/scanner.php @@ -198,6 +198,7 @@ class Scanner extends BasicEmitter implements IScanner { if (!empty($newData)) { $data['fileid'] = $this->addToCache($file, $newData, $fileId); } + $data['oldSize'] = $cacheData['size']; // post-emit only if it was a file. By that we avoid counting/treating folders as files if ($data['mimetype'] !== 'httpd/unix-directory') { diff --git a/lib/private/files/cache/updater.php b/lib/private/files/cache/updater.php index 58d8e53cfd1..80ba704883e 100644 --- a/lib/private/files/cache/updater.php +++ b/lib/private/files/cache/updater.php @@ -118,9 +118,15 @@ class Updater implements IUpdater { } $data = $this->scanner->scan($path, Scanner::SCAN_SHALLOW, -1, false); + if (isset($data['oldSize']) && isset($data['size'])) { + $sizeDifference = $data['size'] - $data['oldSize']; + } else { + // scanner didn't provide size info, fallback to full size calculation + $sizeDifference = 0; + $this->cache->correctFolderSize($path, $data); + } $this->correctParentStorageMtime($path); - $this->cache->correctFolderSize($path, $data); - $this->propagator->propagateChange($path, $time); + $this->propagator->propagateChange($path, $time, $sizeDifference); } /** diff --git a/tests/lib/cache/file.php b/tests/lib/cache/file.php index 0880e7e1282..92b784bf8ea 100644 --- a/tests/lib/cache/file.php +++ b/tests/lib/cache/file.php @@ -87,7 +87,9 @@ class FileCache extends \Test_Cache { } protected function tearDown() { - $this->instance->remove('hack', 'hack'); + if ($this->instance) { + $this->instance->remove('hack', 'hack'); + } \OC_User::setUserId($this->user); \OC::$server->getConfig()->setSystemValue('cachedirectory', $this->datadir); |