Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable10] Optimize PUT - don't fetch and update checksum again, reuse the one from part file #31768

Merged
merged 1 commit into from
Jul 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions apps/dav/lib/Connector/Sabre/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,18 +256,6 @@ public function put($data) {
}

$this->refreshInfo();

$meta = $partStorage->getMetaData($internalPartPath);

if (isset($meta['checksum'])) {
$this->fileView->putFileInfo(
$this->path,
['checksum' => $meta['checksum']]
);
}

$this->refreshInfo();

} catch (StorageNotAvailableException $e) {
throw new ServiceUnavailable("Failed to check file size: " . $e->getMessage());
}
Expand Down
38 changes: 37 additions & 1 deletion lib/private/Files/Stream/Checksum.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,47 @@ private function updateHashingContexts($data) {
}

/**
* Remove .part extension from a file path
* @param string $path Path that may identify a .part file
* @return string File path without .part extension
*/
private function stripPartialFileExtension($path) {
$extension = pathinfo($path, PATHINFO_EXTENSION);

if ( $extension === 'part') {

$newLength = strlen($path) - 5; // 5 = strlen(".part")
$fPath = substr($path, 0, $newLength);

// if path also contains a transaction id, we remove it too
$extension = pathinfo($fPath, PATHINFO_EXTENSION);
if(substr($extension, 0, 12) === 'ocTransferId') { // 12 = strlen("ocTransferId")
$newLength = strlen($fPath) - strlen($extension) -1;
$fPath = substr($fPath, 0, $newLength);
}
return $fPath;

} else {
return $path;
}
}

/**
* Make checksums available for part files and the original file for which part file has been created
* @return bool
*/
public function stream_close() {
$currentPath = $this->getPathFromStreamContext();
self::$checksums[$currentPath] = $this->finalizeHashingContexts();
$checksum = $this->finalizeHashingContexts();
self::$checksums[$currentPath] = $checksum;

// If current path belongs to part file, save checksum for original file
// As a result, call to getChecksums for original file (of this part file) will
// fetch checksum from cache
$originalFilePath = $this->stripPartialFileExtension($currentPath);
if ($originalFilePath !== $currentPath){
self::$checksums[$originalFilePath] = $checksum;
}

return parent::stream_close();
}
Expand Down