1
0
mirror of https://github.com/immich-app/immich.git synced 2024-11-24 08:52:28 +02:00

fix(mobile): fix forgetting backup albums (#3108) (#3244)

This commit is contained in:
Adam Cigánek 2023-07-17 05:08:58 +02:00 committed by GitHub
parent c415ee82d1
commit e287b18435
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -207,6 +207,9 @@ class BackupNotifier extends StateNotifier<BackUpState> {
type: RequestType.common, type: RequestType.common,
); );
// Map of id -> album for quick album lookup later on.
Map<String, AssetPathEntity> albumMap = {};
log.info('Found ${albums.length} local albums'); log.info('Found ${albums.length} local albums');
for (AssetPathEntity album in albums) { for (AssetPathEntity album in albums) {
@ -235,6 +238,8 @@ class BackupNotifier extends StateNotifier<BackUpState> {
} }
availableAlbums.add(availableAlbum); availableAlbums.add(availableAlbum);
albumMap[album.id] = album;
} }
} }
@ -270,30 +275,37 @@ class BackupNotifier extends StateNotifier<BackUpState> {
} }
// Generate AssetPathEntity from id to add to local state // Generate AssetPathEntity from id to add to local state
try { final Set<AvailableAlbum> selectedAlbums = {};
final Set<AvailableAlbum> selectedAlbums = {}; for (final BackupAlbum ba in selectedBackupAlbums) {
for (final BackupAlbum ba in selectedBackupAlbums) { final albumAsset = albumMap[ba.id];
final albumAsset = await AssetPathEntity.fromId(ba.id);
if (albumAsset != null) {
selectedAlbums.add( selectedAlbums.add(
AvailableAlbum(albumEntity: albumAsset, lastBackup: ba.lastBackup), AvailableAlbum(albumEntity: albumAsset, lastBackup: ba.lastBackup),
); );
} else {
log.severe('Selected album not found');
} }
}
final Set<AvailableAlbum> excludedAlbums = {}; final Set<AvailableAlbum> excludedAlbums = {};
for (final BackupAlbum ba in excludedBackupAlbums) { for (final BackupAlbum ba in excludedBackupAlbums) {
final albumAsset = await AssetPathEntity.fromId(ba.id); final albumAsset = albumMap[ba.id];
if (albumAsset != null) {
excludedAlbums.add( excludedAlbums.add(
AvailableAlbum(albumEntity: albumAsset, lastBackup: ba.lastBackup), 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"); debugPrint("_getBackupAlbumsInfo takes ${stopwatch.elapsedMilliseconds}ms");
} }