Ver código fonte

Display accurate sync state

Vishnu Mohandas 4 anos atrás
pai
commit
a5028c9605
2 arquivos alterados com 14 adições e 6 exclusões
  1. 9 2
      lib/db/files_db.dart
  2. 5 4
      lib/photo_sync_manager.dart

+ 9 - 2
lib/db/files_db.dart

@@ -164,11 +164,18 @@ class FilesDB {
     return _convertToFiles(results);
     return _convertToFiles(results);
   }
   }
 
 
-  Future<List<File>> getFilesToBeUploaded() async {
+  Future<List<File>> getFilesToBeUploadedWithinFolders(
+      Set<String> folders) async {
     final db = await instance.database;
     final db = await instance.database;
+    String inParam = "";
+    for (final folder in folders) {
+      inParam += "'" + folder + "',";
+    }
+    inParam = inParam.substring(0, inParam.length - 1);
     final results = await db.query(
     final results = await db.query(
       table,
       table,
-      where: '$columnUploadedFileID IS NULL',
+      where:
+          '$columnUploadedFileID IS NULL AND $columnDeviceFolder IN ($inParam)',
       orderBy: '$columnCreationTime DESC',
       orderBy: '$columnCreationTime DESC',
     );
     );
     return _convertToFiles(results);
     return _convertToFiles(results);

+ 5 - 4
lib/photo_sync_manager.dart

@@ -194,10 +194,11 @@ class PhotoSyncManager {
   }
   }
 
 
   Future<void> _uploadDiff() async {
   Future<void> _uploadDiff() async {
-    List<File> photosToBeUploaded = await _db.getFilesToBeUploaded();
     final foldersToBackUp = Configuration.instance.getFoldersToBackUp();
     final foldersToBackUp = Configuration.instance.getFoldersToBackUp();
-    for (int i = 0; i < photosToBeUploaded.length; i++) {
-      File file = photosToBeUploaded[i];
+    List<File> filesToBeUploaded =
+        await _db.getFilesToBeUploadedWithinFolders(foldersToBackUp);
+    for (int i = 0; i < filesToBeUploaded.length; i++) {
+      File file = filesToBeUploaded[i];
       try {
       try {
         if (!foldersToBackUp.contains(file.deviceFolder)) {
         if (!foldersToBackUp.contains(file.deviceFolder)) {
           continue;
           continue;
@@ -215,7 +216,7 @@ class PhotoSyncManager {
             file.encryptedPassword,
             file.encryptedPassword,
             file.encryptedPasswordIV);
             file.encryptedPasswordIV);
         Bus.instance.fire(PhotoUploadEvent(
         Bus.instance.fire(PhotoUploadEvent(
-            completed: i + 1, total: photosToBeUploaded.length));
+            completed: i + 1, total: filesToBeUploaded.length));
       } catch (e) {
       } catch (e) {
         Bus.instance.fire(PhotoUploadEvent(hasError: true));
         Bus.instance.fire(PhotoUploadEvent(hasError: true));
         throw e;
         throw e;