From 98398ab2febc432581c7b1453b6791b67f59ca55 Mon Sep 17 00:00:00 2001 From: austinried <4966622+austinried@users.noreply.github.com> Date: Mon, 19 Oct 2026 09:50:37 +0000 Subject: [PATCH] library: keep the cached bio on an empty refresh --- .../subtracks/data/repo/LibraryRepository.kt | 5 ++++- .../data/repo/LibraryRepositoryTest.kt | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) 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 {