UploadFileOperation: don't read entire list of uploads every time we want to update the size of just one

Wtf

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
This commit is contained in:
Álvaro Brey 2022-10-27 12:31:18 +02:00
parent 044a321678
commit f83c3aebdc

View file

@ -388,13 +388,7 @@ public class UploadFileOperation extends SyncOperation {
mCancellationRequested.set(false);
mUploadStarted.set(true);
for (OCUpload ocUpload : uploadsStorageManager.getAllStoredUploads()) {
if (ocUpload.getUploadId() == getOCUploadId()) {
ocUpload.setFileSize(0);
uploadsStorageManager.updateUpload(ocUpload);
break;
}
}
updateSize(0);
String remoteParentPath = new File(getRemotePath()).getParent();
remoteParentPath = remoteParentPath.endsWith(OCFile.PATH_SEPARATOR) ?
@ -567,13 +561,8 @@ public class UploadFileOperation extends SyncOperation {
size = new File(mFile.getStoragePath()).length();
}
for (OCUpload ocUpload : uploadsStorageManager.getAllStoredUploads()) {
if (ocUpload.getUploadId() == getOCUploadId()) {
ocUpload.setFileSize(size);
uploadsStorageManager.updateUpload(ocUpload);
break;
}
}
updateSize(size);
/// perform the upload
if (size > ChunkedFileUploadRemoteOperation.CHUNK_SIZE_MOBILE) {
@ -810,13 +799,7 @@ public class UploadFileOperation extends SyncOperation {
size = new File(mFile.getStoragePath()).length();
}
for (OCUpload ocUpload : uploadsStorageManager.getAllStoredUploads()) {
if (ocUpload.getUploadId() == getOCUploadId()) {
ocUpload.setFileSize(size);
uploadsStorageManager.updateUpload(ocUpload);
break;
}
}
updateSize(size);
// perform the upload
if (size > ChunkedFileUploadRemoteOperation.CHUNK_SIZE_MOBILE) {
@ -901,6 +884,14 @@ public class UploadFileOperation extends SyncOperation {
return result;
}
private void updateSize(long size) {
OCUpload ocUpload = uploadsStorageManager.getUploadById(getOCUploadId());
if(ocUpload != null){
ocUpload.setFileSize(size);
uploadsStorageManager.updateUpload(ocUpload);
}
}
private void logResult(RemoteOperationResult result, String sourcePath, String targetPath) {
if (result.isSuccess()) {
Log_OC.i(TAG, "Upload of " + sourcePath + " to " + targetPath + ": " + result.getLogMessage());