diff --git a/app/src/main/kotlin/com/subtracks/data/db/LibraryDao.kt b/app/src/main/kotlin/com/subtracks/data/db/LibraryDao.kt index be480107..16fce628 100644 --- a/app/src/main/kotlin/com/subtracks/data/db/LibraryDao.kt +++ b/app/src/main/kotlin/com/subtracks/data/db/LibraryDao.kt @@ -112,13 +112,13 @@ internal const val CREDITED_ALBUM_ROWS = "JOIN albums ON albums.sourceId = songs.sourceId AND albums.id = songs.albumId " + "WHERE song_artists.sourceId = :sourceId" -// Download visibility follows the credit path: an album credit includes the album when any song is -// downloaded, while a track credit includes it only when the credited track is downloaded. internal const val ALBUMS_FOR_ARTIST = "SELECT albums.* FROM (SELECT DISTINCT albumId FROM ($CREDITED_ALBUM_ROWS) WHERE artistId = :artistId) credits " + "JOIN albums ON albums.sourceId = :sourceId AND albums.id = credits.albumId " + "ORDER BY year DESC, sortName COLLATE NOCASE, id" +// Download visibility follows the credit path: an album credit includes the album when any song is +// downloaded, while a track credit includes it only when the credited track is downloaded. private const val DOWNLOADED_ARTIST_ALBUMS = "SELECT albums.id FROM albums " + "WHERE albums.sourceId = :sourceId AND albums.artistId = artists.id " + diff --git a/app/src/test/kotlin/com/subtracks/data/db/LibraryDaoTest.kt b/app/src/test/kotlin/com/subtracks/data/db/LibraryDaoTest.kt index 79db2354..5beeea79 100644 --- a/app/src/test/kotlin/com/subtracks/data/db/LibraryDaoTest.kt +++ b/app/src/test/kotlin/com/subtracks/data/db/LibraryDaoTest.kt @@ -871,6 +871,8 @@ class LibraryDaoTest { plan, plan.contains("USING INDEX index_song_artists_sourceId_artistId (sourceId=? AND artistId=?)"), ) + assertFalse(plan, plan.contains("SCAN albums")) + assertFalse(plan, plan.contains("SCAN songs")) } private suspend fun plan(sql: String): String = diff --git a/app/src/test/kotlin/com/subtracks/data/sync/SyncServiceTest.kt b/app/src/test/kotlin/com/subtracks/data/sync/SyncServiceTest.kt index 79e18d78..9e446faa 100644 --- a/app/src/test/kotlin/com/subtracks/data/sync/SyncServiceTest.kt +++ b/app/src/test/kotlin/com/subtracks/data/sync/SyncServiceTest.kt @@ -1765,7 +1765,7 @@ class SyncServiceTest { } @Test - fun anIdenticalSyncSkipsTheArtistAggregateQuery() = + fun anIdenticalSyncSkipsTheAggregateQueries() = runTest { val context = ApplicationProvider.getApplicationContext() val executions = Collections.synchronizedList(mutableListOf()) @@ -1786,11 +1786,16 @@ class SyncServiceTest { ) SyncService(loggingDb, source).sync() + val firstSyncExecutions = synchronized(executions) { executions.toList() } + assertTrue(firstSyncExecutions.any { it.sql.contains("credited_albums") }) + assertTrue(firstSyncExecutions.any { it.sql.contains("UPDATE albums SET playCount") }) + synchronized(executions) { executions.clear() } SyncService(loggingDb, source).sync() val secondSyncExecutions = synchronized(executions) { executions.toList() } assertTrue(secondSyncExecutions.none { it.sql.contains("credited_albums") }) + assertTrue(secondSyncExecutions.none { it.sql.contains("UPDATE albums SET playCount") }) } finally { loggingDb.close() }