-
-
Notifications
You must be signed in to change notification settings - Fork 79
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
TUS temporary file optimization (mv instead of read on same filesystem) #1690
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for plone-restapi ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
@JeffersonBledsoe thanks for creating this Pull Request and helping to improve Plone! TL;DR: Finish pushing changes, pass all other checks, then paste a comment:
To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass, but it takes 30-60 min. Other CI checks are usually much faster and the Plone Jenkins resources are limited, so when done pushing changes and all other checks pass either start all Jenkins PR jobs yourself, or simply add the comment above in this PR to start all the jobs automatically. Happy hacking! |
@JeffersonBledsoe NamedBlobFile uses IStorage adapters to process the value that is passed in (https://github.com/plone/plone.namedfile/blob/master/plone/namedfile/storages.py). It might make sense to implement this as an IStorage adapter for TUSUpload.
Yeah, I don't think we can bypass validation entirely. If the entire file is read during validation that's surprising, have you identified where that is happening? |
@davisagli I've put in the storage adapter and that works. I've also put in a test to show it works. But the validation does actually read the whole file into memory (also shown in the test). The cause is
Note this is a problem for NamedImageBlob too. and this is likely a problem for any editing of a File object or other reasons files might be validated Possible solutions?
Not really sure the right way to solve this yet. ideas? |
I also suspect that some of the other storages like FileUploadStorage might also be be already buffered into a local file at least some of the time. In that case, the file can be moved rather than read again improving performance. I haven't looked into this yet however. |
@davisagli I had a go at changing the validation to avoid reading in the whole file in plone/plone.namedfile#155 |
|
||
def store(self, data, blob): | ||
if not isinstance(data, TUSUpload): | ||
raise NotStorable('Could not store data (not of "FileUpload").') |
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.
raise NotStorable('Could not store data (not of "FileUpload").') | |
raise NotStorable('Could not store data (not of type "TUSUpload").') |
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.
@djay Now that I'm looking at things more carefully, I'm wondering if this special storage adapter is really needed.
Previously, an open file was passed into the NamedBlobFile constructor. This should end up using the FileDescriptorStorable which uses blob.consumeFile, which is already using rename_or_copy_blob.
src/plone/restapi/tests/test_tus.py
Outdated
self.assertEqual(blob_read, 0, "Validation is reading the whole blob in memory") | ||
# TODO: would be better test to patch file read instead and ensure its not called? | ||
|
||
ZODB.blob.Blob.open = old_open |
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.
This should go in a finally block in case there's an error during the test.
Plan