diff --git a/app/src/main/kotlin/com/subtracks/data/repo/LibraryRepository.kt b/app/src/main/kotlin/com/subtracks/data/repo/LibraryRepository.kt index 303b6ded..58c75496 100644 --- a/app/src/main/kotlin/com/subtracks/data/repo/LibraryRepository.kt +++ b/app/src/main/kotlin/com/subtracks/data/repo/LibraryRepository.kt @@ -367,8 +367,11 @@ class LibraryRepository( artistId: String, ): Result = try { - val biography = normalizeBiography(sourceRepository.artistBiography(sourceId, artistId)) + val fetched = normalizeBiography(sourceRepository.artistBiography(sourceId, artistId)) val current = db.libraryDao().artistBioOnce(sourceId, artistId) + // An empty response can mean the metadata provider is temporarily down, so keep the + // cached biography instead of erasing it. + val biography = fetched ?: current?.biography if (current == null || current.biography != biography) { db.libraryDao().upsertArtistBio(ArtistBio(sourceId, artistId, biography)) } diff --git a/app/src/test/kotlin/com/subtracks/data/repo/LibraryRepositoryTest.kt b/app/src/test/kotlin/com/subtracks/data/repo/LibraryRepositoryTest.kt index dd5550eb..6dd83601 100644 --- a/app/src/test/kotlin/com/subtracks/data/repo/LibraryRepositoryTest.kt +++ b/app/src/test/kotlin/com/subtracks/data/repo/LibraryRepositoryTest.kt @@ -311,6 +311,24 @@ class LibraryRepositoryTest { } } + @Test + fun anEmptyRefreshKeepsTheStoredBio() = + runBlocking { + withSource { server -> + val sourceId = sourceRepository.activeSourceIdOnce()!! + db.libraryDao().upsertArtistBio(ArtistBio(sourceId, "ar1", "Kept")) + server.enqueue( + MockResponse().setBody( + "", + ), + ) + + assertTrue(repository.refreshArtistBio(sourceId, "ar1").isSuccess) + + assertEquals("Kept", repository.artistBio(sourceId, "ar1").first()?.biography) + } + } + @Test fun aFailedRefreshKeepsTheStoredBio() = runBlocking {