mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-15 00:42:54 +01:00
library: recompute credits when only a lead artist changes
The credit recompute was keyed on song-to-album moves and relation-table writes, so a server that changed songs.artistId or albums.artistId while the plural refs stayed the same left the counts attributed to the old lead. Fold the lead ids into the change check for both songs and albums.
This commit is contained in:
@@ -1636,6 +1636,53 @@ class SyncServiceTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun changingOnlyTheLeadArtistRecomputesTheCreditedCounts() =
|
||||
runTest {
|
||||
insertSource()
|
||||
val source =
|
||||
FakeMusicSource(
|
||||
artists = listOf(artist("a1", "Lead"), artist("a2", "Ref")),
|
||||
albums =
|
||||
listOf(
|
||||
album("al1").copy(
|
||||
artistId = "a1",
|
||||
artists = listOf(ArtistRef("a2", "Ref")),
|
||||
),
|
||||
),
|
||||
songs =
|
||||
listOf(
|
||||
song("s1").copy(
|
||||
albumId = "al1",
|
||||
artistId = "a1",
|
||||
artists = listOf(ArtistRef("a2", "Ref")),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
SyncService(db, source).sync()
|
||||
|
||||
assertEquals(1L, db.libraryDao().artistOnce(1, "a1")!!.songCount)
|
||||
assertEquals(1L, db.libraryDao().artistOnce(1, "a1")!!.albumCount)
|
||||
|
||||
source.albums = listOf(album("al1").copy(artistId = "a2", artists = listOf(ArtistRef("a2", "Ref"))))
|
||||
source.songs =
|
||||
listOf(
|
||||
song("s1").copy(
|
||||
albumId = "al1",
|
||||
artistId = "a2",
|
||||
artists = listOf(ArtistRef("a2", "Ref")),
|
||||
),
|
||||
)
|
||||
|
||||
SyncService(db, source).sync()
|
||||
|
||||
assertEquals(0L, db.libraryDao().artistOnce(1, "a1")!!.songCount)
|
||||
assertEquals(0L, db.libraryDao().artistOnce(1, "a1")!!.albumCount)
|
||||
assertEquals(1L, db.libraryDao().artistOnce(1, "a2")!!.songCount)
|
||||
assertEquals(1L, db.libraryDao().artistOnce(1, "a2")!!.albumCount)
|
||||
}
|
||||
|
||||
private suspend fun totalChanges(): Long =
|
||||
db.useWriterConnection { connection ->
|
||||
connection.usePrepared("SELECT total_changes()") { statement ->
|
||||
|
||||
Reference in New Issue
Block a user