Display the correct queue size

This commit is contained in:
Vishnu Mohandas 2021-03-22 12:44:16 +05:30
parent da47cb7775
commit d1d72ed325
3 changed files with 16 additions and 38 deletions

View file

@ -326,27 +326,6 @@ class FilesDB {
return uploadedFileIDs;
}
Future<int> getNumberOfFilesToBeUploadedOrUpdated(Set<String> 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<int> getNumberOfUploadedFiles() async {
final db = await instance.database;
final rows = await db.query(

View file

@ -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<File> diff, int collectionID) async {
for (File file in diff) {
final existingFiles = await _db.getMatchingFiles(

View file

@ -154,6 +154,10 @@ class FileUploader {
}
}
int queueSize() {
return _queue.length;
}
void clearQueue(final Error reason) {
final uploadsToBeRemoved = List<String>();
_queue.entries