Parcourir la source

Remove any stale enteries in DB

Neeraj Gupta il y a 2 ans
Parent
commit
3dbfb36680
2 fichiers modifiés avec 29 ajouts et 12 suppressions
  1. 21 10
      lib/db/file_updation_db.dart
  2. 8 2
      lib/services/local_file_update_service.dart

+ 21 - 10
lib/db/file_updation_db.dart

@@ -14,16 +14,8 @@ class FileUpdationDB {
   static const tableName = 're_upload_tracker';
   static const columnLocalID = 'local_id';
   static const columnReason = 'reason';
-  static const missingLocation = 'missing_location';
-  static const modificationTimeUpdated = 'modificationTimeUpdated';
-  static const badCreationTime = 'badCreationTime';
-  // refers to the patching of files which had location in exif but the app
-  // did not extracted the location to include it in the file metadata
-  static const missingLocationV2 = 'missingLocationV2';
 
-  // refers to the patching of files which had location in exif but the app
-  // mapped the location to a wrong location
-  static const badLocationCord = 'badLocationCord';
+  static const modificationTimeUpdated = 'modificationTimeUpdated';
 
   // SQL code to create the database table
   static List<String> _createTable() {
@@ -43,7 +35,7 @@ class FileUpdationDB {
         ALTER TABLE $tableName ADD COLUMN $columnReason TEXT;
       ''',
       '''
-        UPDATE $tableName SET $columnReason = '$missingLocation';
+        UPDATE $tableName SET $columnReason = '$modificationTimeUpdated';
       ''',
     ];
   }
@@ -153,6 +145,25 @@ class FileUpdationDB {
     return result;
   }
 
+  // delete entries for given list of reasons
+  Future<void> deleteByReasons(List<String> reasons) async {
+    if (reasons.isEmpty) {
+      return;
+    }
+    String inParam = "";
+    for (final reason in reasons) {
+      inParam += "'" + reason + "',";
+    }
+    inParam = inParam.substring(0, inParam.length - 1);
+    final db = await instance.database;
+    await db.rawQuery(
+      '''
+      DELETE FROM $tableName
+      WHERE $columnReason IN ($inParam);
+    ''',
+    );
+  }
+
   Map<String, dynamic> _getRowForReUploadTable(String localID, String reason) {
     final row = <String, dynamic>{};
     row[columnLocalID] = localID;

+ 8 - 2
lib/services/local_file_update_service.dart

@@ -50,7 +50,7 @@ class LocalFileUpdateService {
     try {
       await _markFilesWhichAreActuallyUpdated();
       if (Platform.isAndroid) {
-        _cleanUpOlderMigration();
+        _cleanUpOlderMigration().ignore();
       }
     } catch (e, s) {
       _logger.severe('failed to perform migration', e, s);
@@ -60,7 +60,7 @@ class LocalFileUpdateService {
     }
   }
 
-  void _cleanUpOlderMigration() {
+  Future<void> _cleanUpOlderMigration() async {
     // check if any old_migration_keys are present in shared preferences
     bool hasOldMigrationKey = false;
     for (String key in _oldMigrationKeys) {
@@ -73,6 +73,12 @@ class LocalFileUpdateService {
       for (var element in _oldMigrationKeys) {
         _prefs.remove(element);
       }
+      await _fileUpdationDB.deleteByReasons([
+        'missing_location',
+        'badCreationTime',
+        'missingLocationV2',
+        'badLocationCord',
+      ]);
     }
   }