-
-
Notifications
You must be signed in to change notification settings - Fork 228
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
Fix import URL eating tons of memory on large file downloads #5826
base: master
Are you sure you want to change the base?
Conversation
🎉 Ta-daaa, freshly created APKs are available for 4f4fc96: arm64-android |
good move |
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.
Good! We need to double check whether the QFC integration does the same.
558b678
to
955a9a4
Compare
1d2113d
to
4f4fc96
Compare
@@ -286,15 +296,18 @@ void AppInterface::importUrl( const QString &url ) | |||
|
|||
QNetworkReply *reply = manager->get( request ); | |||
connect( reply, &QNetworkReply::downloadProgress, this, [=]( int bytesReceived, int bytesTotal ) { | |||
temporaryFile->write( reply->readAll() ); | |||
if ( bytesTotal != 0 ) | |||
{ | |||
emit importProgress( static_cast<double>( bytesReceived ) / bytesTotal ); | |||
} | |||
} ); | |||
|
|||
connect( reply, &QNetworkReply::finished, this, [=]() { |
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.
connect( reply, &QNetworkReply::finished, this, [=]() { | |
std::unique_ptr<QTemporaryFile> temporaryFile = std::make_unique<QTemporaryFile>(); | |
connect( reply, &QNetworkReply::finished, tmpFile = std::move( temporaryFile ), this, [=]() { |
I don't see it bringing many real advantages, but it would be a tiny bit cleaner ... does that 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.
That would scope out at the end of the importUrl function and kill the object no?
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.
There can only be one unique_ptr
wich is moved into the lambda.
The lambda lifetime is bound to the connection.
The connection lifetime is bound to the lifetime of reply
and this
.
But I admit my understanding of this is not 100% water proof.
This PR introduces the use of a temporary file to progressively save data as a file is being downloaded during the import URL process.
This should prevent QField from crashed caused by running out of memory when downloading large files in this process.