address review: NULL disc/track in backward album seeks; drop redundant index

- `albumSongsBefore` used the null-intolerant row-value `<`, so an album
  with NULL `disc`/`track` (untagged files) dropped exactly the rows a
  backward window needs, returning the wrong track at a position. Use a
  NULL-aware predicate (NULL sorts first, so it belongs to any `before`
  set); `albumSongsFrom` is unaffected.
- The new `(sourceId, albumId, disc, track, id)` index has the old
  `(sourceId, albumId)` index as a prefix, so drop the latter in the
  migration and from the entity.
- Tests: mixed NULL disc/track album for the before-window and a full
  backward scan; both fail on the previous commit.
This commit is contained in:
austinried
2026-10-04 00:30:01 +00:00
parent 4aaeb4871b
commit 649528e338
4 changed files with 50 additions and 5 deletions
@@ -266,6 +266,8 @@ val MIGRATION_18_19 =
"CREATE INDEX IF NOT EXISTS `index_songs_sourceId_albumId_order` ON `songs` " +
"(`sourceId`, `albumId`, `disc`, `track`, `id`)",
)
// Covered by the prefix of the new index.
connection.execSQL("DROP INDEX IF EXISTS `index_songs_sourceId_albumId`")
}
}
@@ -125,8 +125,13 @@ interface QueueDao {
limit: Int,
): List<SongListItem>
// Row-value `<` is null-intolerant, and NULL disc/track sort first, so a plain
// `(disc, track, id) < (...)` would drop exactly the untagged tracks a backward window needs.
@Query(
"$ALBUM_SONGS_SELECT AND (songs.disc, songs.track, songs.id) < (:disc, :track, :id) " +
"$ALBUM_SONGS_SELECT AND (" +
"songs.disc IS NULL OR songs.disc < :disc OR " +
"(songs.disc = :disc AND (songs.track IS NULL OR songs.track < :track OR " +
"(songs.track = :track AND songs.id < :id)))) " +
"ORDER BY songs.disc DESC, songs.track DESC, songs.id DESC LIMIT :limit OFFSET :skip",
)
suspend fun albumSongsBefore(
@@ -210,7 +210,6 @@ data class PlaylistSong(
),
],
indices = [
Index("sourceId", "albumId"),
Index("sourceId", "artistId"),
Index(
name = "index_songs_sourceId_albumId_order",