aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2024-01-23 19:39:28 +0100
committerGitHub <noreply@github.com>2024-01-23 19:39:28 +0100
commit8c777145f22fbea2359298466b6b28e9253717fe (patch)
tree6595fcda71102f51bb0af68bcfda8510b8948c2b /lib
parent8ba7de87f56928dccfda492be7da036b61b9ea72 (diff)
parentcc75294eb6b16b916a342e69998935f89222619d (diff)
downloadnextcloud-server-8c777145f22fbea2359298466b6b28e9253717fe.tar.gz
nextcloud-server-8c777145f22fbea2359298466b6b28e9253717fe.zip
Merge pull request #42597 from nextcloud/perf/s3-mkdir-update-size
perf: Avoid updating the folder size if we know the size difference
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Files/Cache/Updater.php26
-rw-r--r--lib/private/Files/View.php8
-rw-r--r--lib/public/Files/Cache/IUpdater.php2
3 files changed, 20 insertions, 16 deletions
diff --git a/lib/private/Files/Cache/Updater.php b/lib/private/Files/Cache/Updater.php
index 457dd207e9d..a6f2f3375a4 100644
--- a/lib/private/Files/Cache/Updater.php
+++ b/lib/private/Files/Cache/Updater.php
@@ -119,7 +119,7 @@ class Updater implements IUpdater {
* @param string $path
* @param int $time
*/
- public function update($path, $time = null) {
+ public function update($path, $time = null, ?int $sizeDifference = null) {
if (!$this->enabled or Scanner::isPartialFile($path)) {
return;
}
@@ -128,20 +128,22 @@ class Updater implements IUpdater {
}
$data = $this->scanner->scan($path, Scanner::SCAN_SHALLOW, -1, false);
- if (
- isset($data['oldSize']) && isset($data['size']) &&
- !$data['encrypted'] // encryption is a pita and touches the cache itself
- ) {
+
+ 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;
- if ($this->cache instanceof Cache) {
- $this->cache->correctFolderSize($path, $data);
- }
+ }
+
+ // encryption is a pita and touches the cache itself
+ if (isset($data['encrypted']) && !!$data['encrypted']) {
+ $sizeDifference = null;
+ }
+
+ // scanner didn't provide size info, fallback to full size calculation
+ if ($this->cache instanceof Cache && $sizeDifference === null) {
+ $this->cache->correctFolderSize($path, $data);
}
$this->correctParentStorageMtime($path);
- $this->propagator->propagateChange($path, $time, $sizeDifference);
+ $this->propagator->propagateChange($path, $time, $sizeDifference ?? 0);
}
/**
diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php
index 6eefb093795..df8990790bb 100644
--- a/lib/private/Files/View.php
+++ b/lib/private/Files/View.php
@@ -287,12 +287,12 @@ class View {
$this->updaterEnabled = true;
}
- protected function writeUpdate(Storage $storage, string $internalPath, ?int $time = null): void {
+ protected function writeUpdate(Storage $storage, string $internalPath, ?int $time = null, ?int $sizeDifference = null): void {
if ($this->updaterEnabled) {
if (is_null($time)) {
$time = time();
}
- $storage->getUpdater()->update($internalPath, $time);
+ $storage->getUpdater()->update($internalPath, $time, $sizeDifference);
}
}
@@ -1173,7 +1173,9 @@ class View {
$this->removeUpdate($storage, $internalPath);
}
if ($result !== false && in_array('write', $hooks, true) && $operation !== 'fopen' && $operation !== 'touch') {
- $this->writeUpdate($storage, $internalPath);
+ $isCreateOperation = $operation === 'mkdir' || ($operation === 'file_put_contents' && in_array('create', $hooks, true));
+ $sizeDifference = $operation === 'mkdir' ? 0 : $result;
+ $this->writeUpdate($storage, $internalPath, null, $isCreateOperation ? $sizeDifference : null);
}
if ($result !== false && in_array('touch', $hooks)) {
$this->writeUpdate($storage, $internalPath, $extraParam);
diff --git a/lib/public/Files/Cache/IUpdater.php b/lib/public/Files/Cache/IUpdater.php
index 5a776d4be7e..625bc91c5a7 100644
--- a/lib/public/Files/Cache/IUpdater.php
+++ b/lib/public/Files/Cache/IUpdater.php
@@ -53,7 +53,7 @@ interface IUpdater {
* @param int $time
* @since 9.0.0
*/
- public function update($path, $time = null);
+ public function update($path, $time = null, ?int $sizeDifference = null);
/**
* Remove $path from the cache and update the size, etag and mtime of the parent folders