Skip to content

Conversation

@deluan
Copy link
Member

@deluan deluan commented Nov 6, 2025

Description

Fix issue where tracks within multi-disc albums were displayed in incorrect order when sorting playlists by album.

Problem

When users sorted playlist tracks by album, tracks from multi-disc albums appeared in the wrong order, ignoring disc numbers and track numbers. For example, track 11 of disc 2 would appear before track 1 of disc 1 instead of appearing after it.

Root Cause

The playlist track repository had an incomplete sort mapping for the 'album' field. It only sorted by album name and album artist, completely missing the critical disc_number and track_number fields.

Solution

Updated the album sort mapping in playlist_track_repository.go to match the sorting pattern used in the media file repository:

Before:

"album": "order_album_name, order_album_artist_name"

After:

"album": "order_album_name, order_album_artist_name, disc_number, track_number, order_artist_name, title"

This ensures consistent sorting across the application, with tracks ordered by:

  1. Album name (groups by album)
  2. Album artist (handles compilations)
  3. Disc number (multi-disc albums in proper order)
  4. Track number (tracks within each disc in order)
  5. Artist name and title (fallback for edge cases with missing metadata)

Changes

  • persistence/playlist_track_repository.go: Updated album sort mapping to include disc_number, track_number, order_artist_name, and title
  • persistence/persistence_suite_test.go: Added multi-disc album test data (albumMultiDisc with 4 test songs)
  • persistence/playlist_repository_test.go: Added comprehensive test for playlist album sorting
  • persistence/mediafile_repository_test.go: Updated media file count (6→10 due to new test songs)
  • persistence/album_repository_test.go: Updated album sort tests to include new multi-disc album

How to Test

  1. Create a playlist with tracks from a multi-disc album in arbitrary order
  2. Sort the playlist by album
  3. Verify tracks appear in correct order: Disc 1 Track 1 → Disc 1 Track 2 → Disc 2 Track 1 → Disc 2 Track 11
  4. All 416 persistence tests pass

Checklist

Please review and check all that apply:

  • My code follows the project's coding style
  • I have tested the changes locally
  • I have added or updated documentation as needed
  • I have added tests that prove my fix/feature works (or explain why not)
  • All existing and new tests pass

Relates to issue #3177

Signed-off-by: Deluan <deluan@navidrome.org>
Signed-off-by: Deluan <deluan@navidrome.org>
Fixed issue #3177 where tracks within multi-disc albums were displayed out of order when sorting playlists by album. The playlist track repository was using an incomplete sort mapping that only sorted by album name and artist, missing the critical disc_number and track_number fields.

Changed the album sort mapping in playlist_track_repository from:
  order_album_name, order_album_artist_name
to:
  order_album_name, order_album_artist_name, disc_number, track_number, order_artist_name, title

This now matches the sorting used in the media file repository, ensuring tracks are sorted by:
1. Album name (groups by album)
2. Album artist (handles compilations)
3. Disc number (multi-disc album discs in order)
4. Track number (tracks within disc in order)
5. Artist name and title (edge cases with missing metadata)

Added comprehensive tests with a multi-disc test album to verify correct sorting behavior.
Copilot AI review requested due to automatic review settings November 6, 2025 16:22
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @deluan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a long-standing bug affecting how tracks from multi-disc albums are ordered within playlists when sorted by album. The core change involves refining the sorting criteria in the playlist track repository to properly account for disc and track numbers, thereby providing users with an accurate and intuitive track listing. The update also includes new test cases to validate the improved sorting logic.

Highlights

  • Playlist Track Sorting Fix: Corrected an issue where tracks within multi-disc albums were displayed in an incorrect order when sorting playlists by album, ignoring disc and track numbers.
  • Root Cause Addressed: The problem stemmed from an incomplete sort mapping for the 'album' field in the playlist track repository, which previously only considered album name and album artist.
  • Enhanced Sorting Logic: The 'album' sort mapping has been updated to include disc_number, track_number, order_artist_name, and title, ensuring a logical and consistent sorting order for multi-disc albums.
  • Comprehensive Testing: New test data for multi-disc albums and a dedicated test case for playlist album sorting have been added to verify the fix and ensure correct behavior.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@deluan deluan linked an issue Nov 6, 2025 that may be closed by this pull request
3 tasks
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively resolves the incorrect track ordering for multi-disc albums in playlists. The solution, which involves updating the sort mapping to include disc_number and track_number, is direct and correct. I appreciate the comprehensive tests you've added, which not only verify the fix but also improve the test suite with multi-disc album data. The changes are clear and well-documented in the pull request description. I have one minor suggestion regarding an unrelated dependency change, but overall, this is a solid contribution.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves playlist track sorting when ordered by album, ensuring tracks from multi-disc albums are sorted correctly by disc number and track number. It also includes a dependency update to fix an issue with the wazero library.

  • Enhanced album sorting to include disc number, track number, artist name, and title for proper multi-disc album ordering
  • Added comprehensive test coverage for multi-disc album sorting in playlists
  • Updated wazero dependency to a fork version to address issue #4396

Reviewed Changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
persistence/playlist_track_repository.go Updated album sort mapping to include disc_number, track_number, order_artist_name, and title
persistence/playlist_repository_test.go Added new test case to verify correct sorting of multi-disc album tracks
persistence/persistence_suite_test.go Added test fixtures for multi-disc album with tracks on different discs
persistence/mediafile_repository_test.go Updated count assertion to account for new test fixtures
persistence/album_repository_test.go Updated test expectations to include new multi-disc test album
go.mod Added replace directive for wazero fork and reformatted existing replace
go.sum Updated checksums for new wazero fork dependency

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@deluan deluan merged commit 4f7dc10 into master Nov 6, 2025
65 of 66 checks passed
@deluan deluan deleted the fix/issue-3177-playlist-album-sorting branch November 6, 2025 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants