[mob][photos] Remove file entry for files that are already queued (#6621)
## Description Potential fix for duplicate file entry on home page. [Discord Ref](https://discord.com/channels/948937918347608085/1397039940692607140/1397039940692607140) ## Tests
This commit is contained in:
@@ -979,6 +979,29 @@ class FilesDB with SqlDbBase {
|
||||
return result;
|
||||
}
|
||||
|
||||
// remove references for local files which are either already uploaded
|
||||
// or queued for upload but not yet uploaded
|
||||
Future<int> removeQueuedLocalFiles(Set<String> localIDs) async {
|
||||
final db = await instance.sqliteAsyncDB;
|
||||
final inParam = localIDs.map((id) => "'$id'").join(',');
|
||||
final r = await db.execute(
|
||||
'''
|
||||
DELETE FROM $filesTable
|
||||
WHERE $columnLocalID IN ($inParam) and (collectionID IS NULL || collectionID = -1)
|
||||
and ($columnUploadedFileID IS NULL OR $columnUploadedFileID = -1);
|
||||
''',
|
||||
);
|
||||
if (r.isNotEmpty) {
|
||||
_logger.warning(
|
||||
"Removed ${r.length} potential dups for already queued local files",
|
||||
);
|
||||
} else {
|
||||
_logger.finest("No duplicate id found for queued/uploaded files");
|
||||
}
|
||||
|
||||
return r.length;
|
||||
}
|
||||
|
||||
Future<Set<String>> getLocalFileIDsForCollection(int collectionID) async {
|
||||
final db = await instance.sqliteAsyncDB;
|
||||
final rows = await db.getAll(
|
||||
|
||||
@@ -371,6 +371,9 @@ class RemoteSyncService {
|
||||
final Set<String> alreadyClaimedLocalIDs =
|
||||
await _db.getLocalIDsMarkedForOrAlreadyUploaded(ownerID);
|
||||
localIDsToSync.removeAll(alreadyClaimedLocalIDs);
|
||||
if (alreadyClaimedLocalIDs.isNotEmpty) {
|
||||
await _db.removeQueuedLocalFiles(alreadyClaimedLocalIDs);
|
||||
}
|
||||
}
|
||||
|
||||
if (localIDsToSync.isEmpty) {
|
||||
|
||||
Reference in New Issue
Block a user