-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix(subsonic): Sort songs by presence of lyrics for getLyrics
#4237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(subsonic): Sort songs by presence of lyrics for getLyrics
#4237
Conversation
The current implementation of `getLyrics` fetches any songs matching the artist and title. However, this misses a case where there may be multiple matches for the same artist/song, and one has lyrics while the other doesn't. Resolve this by adding a custom SQL dynamic column that checks for the presence of lyrics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @kgarner7, 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 addresses an issue in the Subsonic getLyrics
endpoint where, if multiple songs match the same artist and title, the one with lyrics might not be returned. I've introduced a new data access method that specifically sorts matching songs to ensure the one with lyrics is returned first, improving the reliability of the getLyrics
response.
Highlights
- Prioritize songs with lyrics: Modified the
GetLyrics
Subsonic endpoint to fetch songs using a new repository method that sorts results to prioritize entries containing lyrics. - New repository method: Added a new
GetAllByLyrics
method to theMediaFileRepository
interface and its SQL implementation. This method includes a dynamic SQL column to check for non-empty lyrics and orders results based on this column. - Test coverage: Added new test data and a dedicated test case in the persistence layer to verify that
GetAllByLyrics
correctly orders songs, placing those with lyrics first when multiple matches exist. Updated the Subsonic test data and mock implementation to reflect this new 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
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 issue 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 is currently in preview and 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 to provide feedback.
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
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configureGemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
The pull request introduces a new method GetAllByLyrics
to sort songs by the presence of lyrics, which is then used by the Subsonic getLyrics
endpoint. The core idea is sound and addresses the issue of multiple song matches.
My main concerns are with the implementation in persistence/mediafile_repository.go
:
- The
GetAllByLyrics
method currently does not pass theoptions
(containing filters, limits, etc.) to the underlying query builder, which means filters like artist and title will be ignored. - The SQL sorting mechanism
OrderBy("lyrics desc")
might not be universally robust. A more explicitORDER BY (lyrics IS NOT NULL AND lyrics != '[]') DESC
combined with secondary sort criteria from the options would be better.
The tests in persistence/mediafile_repository_test.go
also need adjustment to correctly test the intended behavior, particularly regarding the application of filters and the expectation of receiving songs both with and without lyrics.
The mock implementation in server/subsonic/media_retrieval_test.go
should also be updated to reflect how options (like Max
) are handled by the real method.
Addressing these points will ensure the new functionality is robust and correctly integrated.
Signed-off-by: Deluan <deluan@navidrome.org>
Signed-off-by: Deluan <deluan@navidrome.org>
258af05
to
9bf880d
Compare
/gemini review |
There was a problem hiding this 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 successfully addresses the issue where getLyrics
might return a song without lyrics when multiple matches exist, by prioritizing songs that have lyrics. The changes involve updating the query filter to sort by lyrics presence and updated_at
, adding necessary test data, and implementing a test case to verify the new sorting logic. The mock repository is updated to support this specific sorting for testing purposes. The changes are well-contained and appear correct. No issues of medium, high, or critical severity were found during the review.
There was a problem hiding this 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 enhances the getLyrics
endpoint to prioritize songs that actually have lyrics when multiple matches exist for the same artist/title. It does so by introducing a new filter SongsByArtistTitleWithLyricsFirst
, updating the SQL sort mapping to handle a dynamic “has_lyrics” column, and adding corresponding tests in both the Subsonic controller and the persistence layer.
- Replace
SongWithArtistTitle
withSongsByArtistTitleWithLyricsFirst
inGetLyrics
to sort by lyrics presence first. - Extend mock repository and SQL builder to support sorting on a computed “has_lyrics” column, including tests for parentheses in sort mappings.
- Augment test fixtures across media retrieval and persistence to include scenarios with and without lyrics.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
server/subsonic/media_retrieval_test.go | Updated mock GetAll , added lyrics‐presence test scenarios. |
server/subsonic/media_retrieval.go | Switched to new filter SongsByArtistTitleWithLyricsFirst . |
server/subsonic/filter/filters.go | Renamed/rewrote filter to sort by lyrics presence then updated_at . |
persistence/sql_base_repository_test.go | Added tests for mapping fields with spaces (parentheses). |
persistence/sql_base_repository.go | Documented parentheses requirement in sort mappings. |
persistence/persistence_suite_test.go | Added test media files with lyrics and default "[]" handling. |
persistence/mediafile_repository_test.go | Updated media count test and added repository-level lyrics sort test. |
Comments suppressed due to low confidence (3)
server/subsonic/media_retrieval_test.go:322
- [nitpick] The mock’s sorting logic is only verified for
Order == "desc"
. It would be helpful to add a test forOrder == "asc"
to ensure ascending-order sorting also works correctly.
func (m *mockedMediaFile) GetAll(opts ...model.QueryOptions) (model.MediaFiles, error) {
server/subsonic/media_retrieval_test.go:5
- Importing "cmp" will fail since there is no standard
cmp
package. Please use the correct import path, e.g.,github.com/google/go-cmp/cmp
or another supported comparison utility.
"cmp"
server/subsonic/media_retrieval_test.go:331
- Using string comparison on
Lyrics
to detect presence may misorder items (both start with '['). Consider comparing a boolean flag (e.g.,len(Lyrics) > 2
) to sort by presence of lyrics, then fall back toUpdatedAt
.
diff := cmp.Or(
Signed-off-by: Deluan <deluan@navidrome.org>
The current implementation of
getLyrics
fetches any songs matching the artist and title. However, this misses a case where there may be multiple matches for the same artist/song, and one has lyrics while the other doesn't. Resolve this by adding a custom SQL dynamic column that checks for the presence of lyrics.