diff --git a/lib/db/files_db.dart b/lib/db/files_db.dart index 73536e01b..68bda6141 100644 --- a/lib/db/files_db.dart +++ b/lib/db/files_db.dart @@ -326,27 +326,6 @@ class FilesDB { return uploadedFileIDs; } - Future getNumberOfFilesToBeUploadedOrUpdated(Set folders) async { - if (folders.isEmpty) { - return 0; - } - final db = await instance.database; - String inParam = ""; - for (final folder in folders) { - inParam += "'" + folder + "',"; - } - inParam = inParam.substring(0, inParam.length - 1); - final rows = await db.query( - table, - columns: [columnUploadedFileID], - where: - '($columnLocalID IS NOT NULL AND $columnUploadedFileID IS NOT NULL AND $columnUpdationTime IS NOT NULL AND $columnIsDeleted = 0)', - orderBy: '$columnCreationTime DESC', - distinct: true, - ); - return rows.length; - } - Future getNumberOfUploadedFiles() async { final db = await instance.database; final rows = await db.query( diff --git a/lib/services/sync_service.dart b/lib/services/sync_service.dart index e9c11a999..595717176 100644 --- a/lib/services/sync_service.dart +++ b/lib/services/sync_service.dart @@ -338,12 +338,7 @@ class SyncService { final future = _uploader.upload(file, file.collectionID).then((value) async { uploadCounter++; - final newTotal = await FilesDB.instance.getNumberOfUploadedFiles(); - Bus.instance - .fire(CollectionUpdatedEvent(collectionID: file.collectionID)); - Bus.instance.fire(SyncStatusUpdate(SyncStatus.in_progress, - completed: newTotal - numberOfFilesCurrentlyUploaded, - total: totalUploads)); + await _onFileUploaded(file, numberOfFilesCurrentlyUploaded); }); futures.add(future); } @@ -354,12 +349,7 @@ class SyncService { .id; final future = _uploader.upload(file, collectionID).then((value) async { uploadCounter++; - final newTotal = await FilesDB.instance.getNumberOfUploadedFiles(); - Bus.instance - .fire(CollectionUpdatedEvent(collectionID: file.collectionID)); - Bus.instance.fire(SyncStatusUpdate(SyncStatus.in_progress, - completed: newTotal - numberOfFilesCurrentlyUploaded, - total: totalUploads)); + _onFileUploaded(file, numberOfFilesCurrentlyUploaded); }); futures.add(future); } @@ -376,17 +366,22 @@ class SyncService { } on SilentlyCancelUploadsError { // Do nothing } on UserCancelledUploadError { - totalUploads--; - final newTotal = await FilesDB.instance.getNumberOfUploadedFiles(); - Bus.instance.fire(SyncStatusUpdate(SyncStatus.in_progress, - completed: newTotal - numberOfFilesCurrentlyUploaded, - total: totalUploads)); + // Do nothing } catch (e) { throw e; } return uploadCounter > 0; } + Future _onFileUploaded(File file, int numberOfFilesCurrentlyUploaded) async { + final newTotal = await FilesDB.instance.getNumberOfUploadedFiles(); + Bus.instance.fire(CollectionUpdatedEvent(collectionID: file.collectionID)); + final pendingCount = _uploader.queueSize(); + final completed = newTotal - numberOfFilesCurrentlyUploaded; + Bus.instance.fire(SyncStatusUpdate(SyncStatus.in_progress, + completed: completed, total: completed + pendingCount)); + } + Future _storeDiff(List diff, int collectionID) async { for (File file in diff) { final existingFiles = await _db.getMatchingFiles( diff --git a/lib/utils/file_uploader.dart b/lib/utils/file_uploader.dart index 72573cba7..2b6307ad8 100644 --- a/lib/utils/file_uploader.dart +++ b/lib/utils/file_uploader.dart @@ -154,6 +154,10 @@ class FileUploader { } } + int queueSize() { + return _queue.length; + } + void clearQueue(final Error reason) { final uploadsToBeRemoved = List(); _queue.entries