From e287b184357d56712b3c0d59c8b0bc855a69d40c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Cig=C3=A1nek?= Date: Mon, 17 Jul 2023 05:08:58 +0200 Subject: [PATCH] fix(mobile): fix forgetting backup albums (#3108) (#3244) --- .../backup/providers/backup.provider.dart | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/mobile/lib/modules/backup/providers/backup.provider.dart b/mobile/lib/modules/backup/providers/backup.provider.dart index 835da7960b..0781785b14 100644 --- a/mobile/lib/modules/backup/providers/backup.provider.dart +++ b/mobile/lib/modules/backup/providers/backup.provider.dart @@ -207,6 +207,9 @@ class BackupNotifier extends StateNotifier { type: RequestType.common, ); + // Map of id -> album for quick album lookup later on. + Map albumMap = {}; + log.info('Found ${albums.length} local albums'); for (AssetPathEntity album in albums) { @@ -235,6 +238,8 @@ class BackupNotifier extends StateNotifier { } availableAlbums.add(availableAlbum); + + albumMap[album.id] = album; } } @@ -270,30 +275,37 @@ class BackupNotifier extends StateNotifier { } // Generate AssetPathEntity from id to add to local state - try { - final Set selectedAlbums = {}; - for (final BackupAlbum ba in selectedBackupAlbums) { - final albumAsset = await AssetPathEntity.fromId(ba.id); + final Set selectedAlbums = {}; + for (final BackupAlbum ba in selectedBackupAlbums) { + final albumAsset = albumMap[ba.id]; + + if (albumAsset != null) { selectedAlbums.add( AvailableAlbum(albumEntity: albumAsset, lastBackup: ba.lastBackup), ); + } else { + log.severe('Selected album not found'); } + } - final Set excludedAlbums = {}; - for (final BackupAlbum ba in excludedBackupAlbums) { - final albumAsset = await AssetPathEntity.fromId(ba.id); + final Set excludedAlbums = {}; + for (final BackupAlbum ba in excludedBackupAlbums) { + final albumAsset = albumMap[ba.id]; + + if (albumAsset != null) { excludedAlbums.add( AvailableAlbum(albumEntity: albumAsset, lastBackup: ba.lastBackup), ); + } else { + log.severe('Excluded album not found'); } - state = state.copyWith( - selectedBackupAlbums: selectedAlbums, - excludedBackupAlbums: excludedAlbums, - ); - } catch (e, stackTrace) { - log.severe("Failed to generate album from id", e, stackTrace); } + state = state.copyWith( + selectedBackupAlbums: selectedAlbums, + excludedBackupAlbums: excludedAlbums, + ); + debugPrint("_getBackupAlbumsInfo takes ${stopwatch.elapsedMilliseconds}ms"); }