From 927e1fef803d2a2ad590dbd7a49b66e4a85b24bf Mon Sep 17 00:00:00 2001 From: Prateek Sunal Date: Thu, 31 Jul 2025 17:40:55 +0530 Subject: [PATCH] fix: only delete if collection is deleted or null --- .../lib/services/smart_albums_service.dart | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/mobile/apps/photos/lib/services/smart_albums_service.dart b/mobile/apps/photos/lib/services/smart_albums_service.dart index e602ed0825..2f0998a579 100644 --- a/mobile/apps/photos/lib/services/smart_albums_service.dart +++ b/mobile/apps/photos/lib/services/smart_albums_service.dart @@ -86,24 +86,35 @@ class SmartAlbumsService { return; } - _logger.info("Syncing Smart Albums"); + _logger.fine("Syncing Smart Albums"); final cachedConfigs = await getSmartConfigs(); final userId = Configuration.instance.getUserID()!; for (final entry in cachedConfigs.entries) { final collectionId = entry.key; final config = entry.value; + + if (config.personIDs.isEmpty) { + _logger.warning( + "Skipping sync for collection ($collectionId) as it has no person IDs", + ); + continue; + } + final collection = CollectionsService.instance.getCollectionByID(collectionId); - if (!(collection?.canAutoAdd(userId) ?? false)) { + if (collection == null || !collection.canAutoAdd(userId)) { _logger.warning( - "Deleting collection config ($collectionId) as user does not have permission", - ); - await _deleteEntry( - userId: userId, - collectionId: collectionId, + "For config ($collectionId) user does not have permission", ); + if (collection?.isDeleted ?? true) { + await _deleteEntry( + userId: userId, + collectionId: collectionId, + ); + } + continue; } @@ -174,7 +185,7 @@ class SmartAlbumsService { } syncingCollection = null; Bus.instance.fire(SmartAlbumSyncingEvent()); - _logger.info("Smart Albums sync completed"); + _logger.fine("Smart Albums sync completed"); } Future addPeopleToSmartAlbum( @@ -218,11 +229,6 @@ class SmartAlbumsService { addWithCustomID: config.id == null, userId: userId, ); - } else if (config.id != null) { - await _deleteEntry( - userId: userId, - collectionId: config.collectionId, - ); } } @@ -242,6 +248,7 @@ class SmartAlbumsService { bool addWithCustomID = false, required int userId, }) async { + _logger.fine("Adding or updating entity for collection ($collectionId)"); final id = getId(collectionId: collectionId, userId: userId); final result = await entityService.addOrUpdate( type, @@ -258,6 +265,7 @@ class SmartAlbumsService { required int userId, required int collectionId, }) async { + _logger.fine("Deleting entry for collection ($collectionId)"); final id = getId(collectionId: collectionId, userId: userId); await entityService.deleteEntry(id); _lastCacheRefreshTime = 0; // Invalidate cache