mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-15 00:42:54 +01:00
library: fix sort-name resolution and migration rebuild
Collect every credited artist id when resolving album and song sort keys so the singular id and plural refs can both be looked up, and add regression tests for the compilation and stale-sort-name cases. Drop the FTS tables before the backfill so the old triggers do not index rows that are about to be discarded, and rely on createSearchIndex's rebuild instead of rebuilding a second time. Treat a whitespace-only artist sortName as absent, and use the sort keys in the downloads tree too.
This commit is contained in:
@@ -985,31 +985,43 @@ class LibraryDaoTest {
|
||||
val dao = db.libraryDao()
|
||||
dao.upsertArtists(
|
||||
listOf(
|
||||
artist(sourceId, "ar-1", "宇多田ヒカル", albumCount = 1).copy(sortName = "Utada Hikaru"),
|
||||
artist(sourceId, "ar-2", "あいみょん", albumCount = 1).copy(sortName = "Aimyon"),
|
||||
artist(sourceId, "ar-1", "あいみょん", albumCount = 1).copy(sortName = "Zzz"),
|
||||
artist(sourceId, "ar-2", "宇多田ヒカル", albumCount = 1).copy(sortName = "Aaa"),
|
||||
),
|
||||
)
|
||||
dao.upsertAlbums(
|
||||
listOf(
|
||||
album(sourceId, "al-1", "First Love", year = null, starred = null)
|
||||
.copy(sortName = "First Love", albumArtistSort = "Utada Hikaru"),
|
||||
album(sourceId, "al-2", "Zutto", year = null, starred = null)
|
||||
.copy(sortName = "Zutto", albumArtistSort = "Aimyon"),
|
||||
album(sourceId, "al-1", "Zzz", year = null, starred = null)
|
||||
.copy(sortName = "Aaa", albumArtistSort = "Zzz"),
|
||||
album(sourceId, "al-2", "Aaa", year = null, starred = null)
|
||||
.copy(sortName = "Zzz", albumArtistSort = "Aaa"),
|
||||
),
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
listOf("あいみょん", "宇多田ヒカル"),
|
||||
listOf("宇多田ヒカル", "あいみょん"),
|
||||
dao.artistsByName(sourceId, 0, "").page().map { it.name },
|
||||
)
|
||||
assertEquals(
|
||||
listOf("First Love", "Zutto"),
|
||||
listOf("あいみょん", "宇多田ヒカル"),
|
||||
dao.artistsByNameReversed(sourceId, 0, "").page().map { it.name },
|
||||
)
|
||||
assertEquals(
|
||||
listOf("Zzz", "Aaa"),
|
||||
dao.albumsByName(sourceId, 0, "").page().map { it.name },
|
||||
)
|
||||
assertEquals(
|
||||
listOf("Zutto", "First Love"),
|
||||
listOf("Aaa", "Zzz"),
|
||||
dao.albumsByNameReversed(sourceId, 0, "").page().map { it.name },
|
||||
)
|
||||
assertEquals(
|
||||
listOf("Aaa", "Zzz"),
|
||||
dao.albumsByArtist(sourceId, 0, "").page().map { it.name },
|
||||
)
|
||||
assertEquals(
|
||||
listOf("Zzz", "Aaa"),
|
||||
dao.albumsByArtistReversed(sourceId, 0, "").page().map { it.name },
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -993,6 +993,77 @@ class SyncServiceTest {
|
||||
assertEquals("Utada Hikaru", db.libraryDao().songOnce(1, "s1")!!.artistSort)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun songArtistSortUsesTheSingularArtistOverThePluralList() =
|
||||
runTest {
|
||||
insertSource()
|
||||
val source =
|
||||
FakeMusicSource(
|
||||
artists =
|
||||
listOf(
|
||||
artist("a1", "A").copy(sortName = "Alpha"),
|
||||
artist("a2", "B").copy(sortName = "Beta"),
|
||||
),
|
||||
albums = listOf(album("al1")),
|
||||
songs =
|
||||
listOf(
|
||||
song("s1").copy(
|
||||
artistId = "a2",
|
||||
artists = listOf(ArtistRef("a1", "A"), ArtistRef("a2", "B")),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
SyncService(db, source).sync()
|
||||
|
||||
assertEquals("Beta", db.libraryDao().songOnce(1, "s1")!!.artistSort)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun albumArtistSortFallsBackToAPluralRefWhenTheSingularArtistIsMissing() =
|
||||
runTest {
|
||||
insertSource()
|
||||
val source =
|
||||
FakeMusicSource(
|
||||
artists = listOf(artist("a1", "A").copy(sortName = "Alpha")),
|
||||
albums =
|
||||
listOf(
|
||||
album("al1").copy(
|
||||
artistId = "missing",
|
||||
albumArtist = "A",
|
||||
artists = listOf(ArtistRef("a1", "A")),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
SyncService(db, source).sync()
|
||||
|
||||
assertEquals("Alpha", db.libraryDao().albumOnce(1, "al1")!!.albumArtistSort)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun changingAnArtistSortNameUpdatesAlbumAndSongSortKeys() =
|
||||
runTest {
|
||||
insertSource()
|
||||
val source =
|
||||
FakeMusicSource(
|
||||
artists = listOf(artist("a1", "A").copy(sortName = "Alpha")),
|
||||
albums = listOf(album("al1")),
|
||||
songs = listOf(song("s1")),
|
||||
)
|
||||
|
||||
SyncService(db, source).sync()
|
||||
assertEquals("Alpha", db.libraryDao().albumOnce(1, "al1")!!.albumArtistSort)
|
||||
assertEquals("Alpha", db.libraryDao().songOnce(1, "s1")!!.artistSort)
|
||||
|
||||
source.artists = listOf(artist("a1", "A").copy(sortName = "Zulu"))
|
||||
|
||||
SyncService(db, source).sync()
|
||||
|
||||
assertEquals("Zulu", db.libraryDao().albumOnce(1, "al1")!!.albumArtistSort)
|
||||
assertEquals("Zulu", db.libraryDao().songOnce(1, "s1")!!.artistSort)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun everyAlbumArtistAndTrackArtistReachesTheSharedAlbum() =
|
||||
runTest {
|
||||
|
||||
Reference in New Issue
Block a user