From deb3b8b46b573901a484c050f0654d2c7d12611a Mon Sep 17 00:00:00 2001 From: Piotr M Date: Wed, 29 Mar 2017 10:54:59 +0200 Subject: [PATCH] Optimize PUT - dont fetch and update checksum again, reunse the one from part file --- apps/dav/lib/Connector/Sabre/File.php | 12 --------- lib/private/Files/Stream/Checksum.php | 38 ++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/apps/dav/lib/Connector/Sabre/File.php b/apps/dav/lib/Connector/Sabre/File.php index 75cc5779100a..b6f0d1d32215 100644 --- a/apps/dav/lib/Connector/Sabre/File.php +++ b/apps/dav/lib/Connector/Sabre/File.php @@ -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()); } diff --git a/lib/private/Files/Stream/Checksum.php b/lib/private/Files/Stream/Checksum.php index 43bc454a7d2c..9be7e8eb3b2a 100644 --- a/lib/private/Files/Stream/Checksum.php +++ b/lib/private/Files/Stream/Checksum.php @@ -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(); }