Skip to content

Commit cc7c467

Browse files
committed
Pass size difference for mkdir/file_put_content operations to speed up correcting the folder size
Signed-off-by: Julius Härtl <jus@bitgrid.net>
1 parent 834d081 commit cc7c467

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

lib/private/Files/View.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
use OC\Files\Storage\Storage;
5252
use OC\User\LazyUser;
5353
use OC\Share\Share;
54-
use OC\User\User;
5554
use OCA\Files_Sharing\SharedMount;
5655
use OCP\Constants;
5756
use OCP\Files\Cache\ICacheEntry;
@@ -316,12 +315,12 @@ public function enableCacheUpdate() {
316315
$this->updaterEnabled = true;
317316
}
318317

319-
protected function writeUpdate(Storage $storage, $internalPath, $time = null) {
318+
protected function writeUpdate(Storage $storage, $internalPath, $time = null, $size = null) {
320319
if ($this->updaterEnabled) {
321320
if (is_null($time)) {
322321
$time = time();
323322
}
324-
$storage->getUpdater()->update($internalPath, $time);
323+
$storage->getUpdater()->update($internalPath, $time, $size);
325324
}
326325
}
327326

@@ -1175,6 +1174,7 @@ private function basicOperation($operation, $path, $hooks = [], $extraParam = nu
11751174
$this->unlockFile($path, ILockingProvider::LOCK_SHARED);
11761175
throw $e;
11771176
}
1177+
$previousSize = $storage->filesize($internalPath);
11781178
}
11791179
try {
11801180
if (!is_null($extraParam)) {
@@ -1195,7 +1195,13 @@ private function basicOperation($operation, $path, $hooks = [], $extraParam = nu
11951195
$this->removeUpdate($storage, $internalPath);
11961196
}
11971197
if ($result !== false && in_array('write', $hooks, true) && $operation !== 'fopen' && $operation !== 'touch') {
1198-
$this->writeUpdate($storage, $internalPath);
1198+
$size = null;
1199+
if ($operation === 'mkdir') {
1200+
$size = 0;
1201+
} elseif ($operation === 'file_put_contents' && isset($previousSize)) {
1202+
$size = $result - $previousSize;
1203+
}
1204+
$this->writeUpdate($storage, $internalPath, null, $size);
11991205
}
12001206
if ($result !== false && in_array('touch', $hooks)) {
12011207
$this->writeUpdate($storage, $internalPath, $extraParam);

0 commit comments

Comments
 (0)