mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-11 15:29:15 +01:00
library: keep the cached bio on an empty refresh
This commit is contained in:
@@ -367,8 +367,11 @@ class LibraryRepository(
|
|||||||
artistId: String,
|
artistId: String,
|
||||||
): Result<Unit> =
|
): Result<Unit> =
|
||||||
try {
|
try {
|
||||||
val biography = normalizeBiography(sourceRepository.artistBiography(sourceId, artistId))
|
val fetched = normalizeBiography(sourceRepository.artistBiography(sourceId, artistId))
|
||||||
val current = db.libraryDao().artistBioOnce(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) {
|
if (current == null || current.biography != biography) {
|
||||||
db.libraryDao().upsertArtistBio(ArtistBio(sourceId, artistId, biography))
|
db.libraryDao().upsertArtistBio(ArtistBio(sourceId, artistId, biography))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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(
|
||||||
|
"<subsonic-response status=\"ok\"><artistInfo2/></subsonic-response>",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
assertTrue(repository.refreshArtistBio(sourceId, "ar1").isSuccess)
|
||||||
|
|
||||||
|
assertEquals("Kept", repository.artistBio(sourceId, "ar1").first()?.biography)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun aFailedRefreshKeepsTheStoredBio() =
|
fun aFailedRefreshKeepsTheStoredBio() =
|
||||||
runBlocking {
|
runBlocking {
|
||||||
|
|||||||
Reference in New Issue
Block a user