-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Optimize PUT - don't fetch and update checksum again, reunse the one from part file #27532
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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(); | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to me some kind of workaround for some purpose, probably for what I have erased to work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from my understanding this is necessary if the file was changed on disk which is detected by the scanner.
in this case the checksum has to be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just went with debugger, first time the PUT gets there is with
core/apps/dav/lib/Connector/Sabre/File.php
Line 204 in 186595c
core/lib/private/Files/Cache/Scanner.php
Line 204 in 186595c
Next time it gets there is in
core/apps/dav/lib/Connector/Sabre/File.php
Line 215 in 186595c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DeepDiver1975 any thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot think where cleaning of checksum might be usefull, first call goes through
core/lib/private/Files/Cache/Scanner.php
Line 200 in 186595c
core/lib/private/Files/Cache/Scanner.php
Line 180 in 186595c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you retest with an external storage ? Then change a file directly on external storage and run occ files:scan. In this case, the checksum in oc_filecache must disappear since the file changed and we didn't recompute it yet.
If this still works correctly then maybe there is yet another code paths that achieves the same result... strange
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also beware, when testing uploads, always test these:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please make sure these are covered by integration tests + checksums to make sure this PR doesn't break anything