Remove any stale enteries in DB

This commit is contained in:
Neeraj Gupta 2023-05-24 12:23:33 +05:30
parent aaa1036e3a
commit 3dbfb36680
2 changed files with 29 additions and 12 deletions

View file

@ -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;

View file

@ -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',
]);
}
}