clear up stale album id

This commit is contained in:
Alex
2026-01-23 12:10:29 -06:00
parent 5ce6fff16e
commit 77936e2421
2 changed files with 19 additions and 0 deletions

View File

@@ -123,6 +123,16 @@ class CleanupNotifier extends StateNotifier<CleanupState> {
_appSettingsService.setSetting(AppSettingsEnum.cleanupKeepAlbumIds, albumIds.join(','));
}
/// Remove album IDs that no longer exist on the device
void cleanupStaleAlbumIds(Set<String> existingAlbumIds) {
final staleIds = state.keepAlbumIds.difference(existingAlbumIds);
if (staleIds.isNotEmpty) {
final cleanedIds = state.keepAlbumIds.intersection(existingAlbumIds);
state = state.copyWith(keepAlbumIds: cleanedIds);
_persistExcludedAlbumIds(cleanedIds);
}
}
Future<void> scanAssets() async {
if (_userId == null || state.selectedDate == null) {
return;

View File

@@ -779,6 +779,15 @@ class _KeepAlbumsSection extends ConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
final albumsAsync = ref.watch(localAlbumProvider);
// Clean up stale album IDs when albums are loaded
albumsAsync.whenData((albums) {
final existingAlbumIds = albums.map((a) => a.id).toSet();
// Use Future.microtask to avoid modifying state during build
Future.microtask(() {
ref.read(cleanupProvider.notifier).cleanupStaleAlbumIds(existingAlbumIds);
});
});
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [