Skip to content

Commit

Permalink
Already pass size difference to the cache updater to avoid full calcu…
Browse files Browse the repository at this point in the history
…lation on s3

Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliusknorr committed Aug 5, 2021
1 parent 2a63219 commit 1a3e4c5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion apps/dav/lib/Connector/Sabre/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ public function put($data) {
$this->header('X-Hash-SHA256: ' . $hash);
});

$previousFileSize = $exists ? $partStorage->filesize($internalPath) : 0;
if ($partStorage->instanceOfStorage(Storage\IWriteStreamStorage::class)) {
$isEOF = false;
$wrappedData = CallbackWrapper::wrap($data, null, null, null, null, function ($stream) use (&$isEOF) {
Expand Down Expand Up @@ -306,7 +307,7 @@ public function put($data) {
}

// since we skipped the view we need to scan and emit the hooks ourselves
$storage->getUpdater()->update($internalPath);
$storage->getUpdater()->update($internalPath, null, ($count-$previousFileSize));

try {
$this->changeLock(ILockingProvider::LOCK_SHARED);
Expand Down
12 changes: 7 additions & 5 deletions lib/private/Files/Cache/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ public function propagate($path, $time = null) {
*
* @param string $path
* @param int $time
* @param int $sizeDifference
*/
public function update($path, $time = null) {
public function update($path, $time = null, $sizeDifference = null) {
if (!$this->enabled or Scanner::isPartialFile($path)) {
return;
}
Expand All @@ -129,14 +130,15 @@ public function update($path, $time = null) {
) {
$sizeDifference = $data['size'] - $data['oldSize'];
} else {
// scanner didn't provide size info, fallback to full size calculation
$sizeDifference = 0;
if ($this->cache instanceof Cache) {
// scanner didn't provide size info, fallback to full size calculation if the difference was not already passed
// otherwise we can update through the propagator
if ($this->cache instanceof Cache && $sizeDifference === null) {
$this->cache->correctFolderSize($path, $data);
$sizeDifference = 0;
}
}
$this->correctParentStorageMtime($path);
$this->propagator->propagateChange($path, $time, $sizeDifference);
$this->propagator->propagateChange($path, $time, $sizeDifference ?? 0);
}

/**
Expand Down

0 comments on commit 1a3e4c5

Please sign in to comment.