From b58aeddeba45728c47fb9233f79c9a2275ea6146 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Thu, 24 Jul 2025 11:27:49 +0530 Subject: [PATCH] [mob][photos] Remove file entry for files that are already queued --- mobile/apps/photos/lib/db/files_db.dart | 23 +++++++++++++++++++ .../services/sync/remote_sync_service.dart | 3 +++ 2 files changed, 26 insertions(+) diff --git a/mobile/apps/photos/lib/db/files_db.dart b/mobile/apps/photos/lib/db/files_db.dart index f8900f8912..3150dbc3b6 100644 --- a/mobile/apps/photos/lib/db/files_db.dart +++ b/mobile/apps/photos/lib/db/files_db.dart @@ -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 removeQueuedLocalFiles(Set 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> getLocalFileIDsForCollection(int collectionID) async { final db = await instance.sqliteAsyncDB; final rows = await db.getAll( diff --git a/mobile/apps/photos/lib/services/sync/remote_sync_service.dart b/mobile/apps/photos/lib/services/sync/remote_sync_service.dart index d4523b27d0..d0e995a438 100644 --- a/mobile/apps/photos/lib/services/sync/remote_sync_service.dart +++ b/mobile/apps/photos/lib/services/sync/remote_sync_service.dart @@ -371,6 +371,9 @@ class RemoteSyncService { final Set alreadyClaimedLocalIDs = await _db.getLocalIDsMarkedForOrAlreadyUploaded(ownerID); localIDsToSync.removeAll(alreadyClaimedLocalIDs); + if (alreadyClaimedLocalIDs.isNotEmpty) { + await _db.removeQueuedLocalFiles(alreadyClaimedLocalIDs); + } } if (localIDsToSync.isEmpty) {