diff --git a/lib/db/file_updation_db.dart b/lib/db/file_updation_db.dart index 5d69fe8b4..22f317924 100644 --- a/lib/db/file_updation_db.dart +++ b/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 _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 deleteByReasons(List 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 _getRowForReUploadTable(String localID, String reason) { final row = {}; row[columnLocalID] = localID; diff --git a/lib/services/local_file_update_service.dart b/lib/services/local_file_update_service.dart index b7201643d..1ad4f0f56 100644 --- a/lib/services/local_file_update_service.dart +++ b/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 _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', + ]); } }