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:
austinried
2026-10-18 14:47:00 +00:00
parent 65d74faa1d
commit d03dd982b2
2 changed files with 79 additions and 8 deletions
@@ -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 ->