From a4bb57822a93eedec41738fe4127d29019045614 Mon Sep 17 00:00:00 2001 From: Barnabas Balogh Date: Tue, 21 Jul 2026 16:46:33 +0000 Subject: [PATCH] fix(catalog): preserve cached episodes when refreshing seasons --- .../data/catalog/InMemoryLocalMediaRepository.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/data/src/main/java/hu/bbara/purefin/data/catalog/InMemoryLocalMediaRepository.kt b/data/src/main/java/hu/bbara/purefin/data/catalog/InMemoryLocalMediaRepository.kt index b652eed4..d6893c93 100644 --- a/data/src/main/java/hu/bbara/purefin/data/catalog/InMemoryLocalMediaRepository.kt +++ b/data/src/main/java/hu/bbara/purefin/data/catalog/InMemoryLocalMediaRepository.kt @@ -145,8 +145,16 @@ class InMemoryLocalMediaRepository @Inject constructor( series = seriesState.first()[seriesId] ?: throw RuntimeException("Series not found") } + val existingSeasonsById = series.seasons.associateBy { it.id } val updatedSeries = series.copy( - seasons = jellyfinApiClient.getSeasons(seriesId).map { it.toSeason() } + seasons = jellyfinApiClient.getSeasons(seriesId).map { it.toSeason() }.map { fresh -> + val existing = existingSeasonsById[fresh.id] + if (existing != null && existing.episodes.isNotEmpty()) { + fresh.copy(episodes = existing.episodes) + } else { + fresh + } + } ) seriesState.update { it + (updatedSeries.id to updatedSeries) } } catch (error: CancellationException) {