diff options
author | Vincent Petry <vincent@nextcloud.com> | 2022-08-17 09:21:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-17 09:21:30 +0200 |
commit | 082432e01cb3cb614139d285b769cb3f68310748 (patch) | |
tree | fa2c98c6fb2e96c4208dde42223059f90a0ecefc /lib/private/Files/Cache | |
parent | 58fb55febe662f2e208ae71f596b1a8881ed2298 (diff) | |
parent | 457822c1444d3e8b543e029e729b35727a66fad0 (diff) | |
download | nextcloud-server-082432e01cb3cb614139d285b769cb3f68310748.tar.gz nextcloud-server-082432e01cb3cb614139d285b769cb3f68310748.zip |
Merge pull request #33551 from nextcloud/scanner-dont-update-same-size
don't update the folder size if we know it hasn't changed
Diffstat (limited to 'lib/private/Files/Cache')
-rw-r--r-- | lib/private/Files/Cache/Scanner.php | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/private/Files/Cache/Scanner.php b/lib/private/Files/Cache/Scanner.php index fb32b64c012..4799c3bff7d 100644 --- a/lib/private/Files/Cache/Scanner.php +++ b/lib/private/Files/Cache/Scanner.php @@ -339,7 +339,7 @@ class Scanner extends BasicEmitter implements IScanner { try { $data = $this->scanFile($path, $reuse, -1, null, $lock); if ($data and $data['mimetype'] === 'httpd/unix-directory') { - $size = $this->scanChildren($path, $recursive, $reuse, $data['fileid'], $lock); + $size = $this->scanChildren($path, $recursive, $reuse, $data['fileid'], $lock, $data); $data['size'] = $size; } } finally { @@ -376,9 +376,10 @@ class Scanner extends BasicEmitter implements IScanner { * @param int $reuse * @param int $folderId id for the folder to be scanned * @param bool $lock set to false to disable getting an additional read lock during scanning + * @param array $data the data of the folder before (re)scanning the children * @return int the size of the scanned folder or -1 if the size is unknown at this stage */ - protected function scanChildren($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $folderId = null, $lock = true) { + protected function scanChildren($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $folderId = null, $lock = true, array $data = []) { if ($reuse === -1) { $reuse = ($recursive === self::SCAN_SHALLOW) ? self::REUSE_ETAG | self::REUSE_SIZE : self::REUSE_ETAG; } @@ -397,7 +398,8 @@ class Scanner extends BasicEmitter implements IScanner { $size += $childSize; } } - if ($this->cacheActive) { + $oldSize = $data['size'] ?? null; + if ($this->cacheActive && $oldSize !== $size) { $this->cache->update($folderId, ['size' => $size]); } $this->emit('\OC\Files\Cache\Scanner', 'postScanFolder', [$path, $this->storageId]); @@ -409,6 +411,11 @@ class Scanner extends BasicEmitter implements IScanner { $existingChildren = $this->getExistingChildren($folderId); $newChildren = iterator_to_array($this->storage->getDirectoryContent($path)); + if (count($existingChildren) === 0 && count($newChildren) === 0) { + // no need to do a transaction + return []; + } + if ($this->useTransactions) { \OC::$server->getDatabaseConnection()->beginTransaction(); } |