Skip to content

feat: implement RecentlyAddedByModTime support for tracks (#4046) #4279

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

Merged
merged 3 commits into from
Jun 30, 2025

Conversation

deluan
Copy link
Member

@deluan deluan commented Jun 29, 2025

This PR fixes issue #4046 by implementing RecentlyAddedByModTime configuration support for individual tracks/mediafiles.

Problem

The RecentlyAddedByModTime configuration setting only worked for albums, not for individual tracks. When sorting tracks by "Date Added", the system would always use created_at regardless of the configuration setting.

Solution

Backend Changes

  • Added mediaFileRecentlyAddedSort() function to respect the RecentlyAddedByModTime configuration
  • Added recently_added sort mapping to mediafile repository that uses modification time when configured
  • Implemented proper test coverage for both configuration scenarios

Frontend Changes

  • Updated SongList.jsx to use sortBy="recently_added" for the "Date Added" column
  • This ensures the UI uses the correct backend sort key that respects the configuration

Closes #4046

deluan added 2 commits June 29, 2025 18:05
Fixes #4046 by adding recently_added sort mapping to MediaFileRepository that respects the RecentlyAddedByModTime configuration setting. Previously, this feature only worked for albums, causing inconsistent behavior when clients requested tracks sorted by 'recently added'.

Changes include:
- Add mediaFileRecentlyAddedSort() function that returns 'updated_at' when RecentlyAddedByModTime=true, 'created_at' otherwise
- Add 'recently_added' sort mapping to mediafile repository
- Add comprehensive tests to verify both configuration scenarios

This ensures consistent sorting behavior between albums and tracks when using the RecentlyAddedByModTime feature.
Modified the createdAt field in the SongList component to include a sortBy
attribute set to "recently_added". This change ensures that the media files
are displayed in the order they were added, improving the user experience
when browsing through recently added items.

Signed-off-by: Deluan <deluan@navidrome.org>
@Copilot Copilot AI review requested due to automatic review settings June 29, 2025 22:17
Copy link
Contributor

@Copilot 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 fixes issue #4046 by updating the recently added sorting behavior for tracks, ensuring the system uses the proper timestamp based on configuration.

  • Updated SongList.jsx to pass the sort key "recently_added" for the "Date Added" column.
  • Added backend support in mediafile_repository.go with a new mediaFileRecentlyAddedSort() function.
  • Introduced test cases in mediafile_repository_test.go for both configuration scenarios.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
ui/src/song/SongList.jsx Updated DateField to sort tracks using "recently_added" sort key.
persistence/mediafile_repository_test.go Added tests for sorting behavior with different configuration settings.
persistence/mediafile_repository.go Implemented mediaFileRecentlyAddedSort() function to return the correct sort field.
Comments suppressed due to low confidence (2)

ui/src/song/SongList.jsx:186

  • It would be helpful to add an inline comment explaining that the sortBy prop 'recently_added' is used to respect the RecentlyAddedByModTime configuration, especially since the displayed source remains 'createdAt'.
        <DateField source="createdAt" sortBy="recently_added" showTime />

persistence/mediafile_repository_test.go:167

  • Consider enhancing the tests to verify not just that results are returned, but that the ordering of the results is correct according to the configuration (i.e., check that the sort order changes between created_at and updated_at based on RecentlyAddedByModTime).
			results, err := mr.GetAll(model.QueryOptions{Sort: "recently_added", Order: "desc"})

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.

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 addresses a long-standing issue where the 'Date Added' sorting for individual tracks did not honor the RecentlyAddedByModTime server configuration. It introduces the necessary backend logic to allow tracks to be sorted by their modification time when the setting is enabled, and updates the frontend to correctly request this new sorting behavior, providing a consistent and configurable 'recently added' experience across the application.

Highlights

  • Track Sorting Logic Enhancement: Implemented a new backend function, mediaFileRecentlyAddedSort(), that dynamically determines whether to sort individual tracks by their updated_at (modification time) or created_at timestamp. This decision is based on the RecentlyAddedByModTime server configuration setting.
  • Backend Sort Key Integration: Updated the mediafile repository to include a new recently_added sort mapping. This mapping now leverages the dynamic logic provided by mediaFileRecentlyAddedSort() to ensure that track sorting respects the configured preference for 'recently added' items.
  • Frontend UI Alignment: Modified the SongList.jsx component in the frontend. The 'Date Added' column now explicitly uses the sortBy="recently_added" key when requesting data from the backend, ensuring that the user interface correctly reflects the server's configured sorting behavior for tracks.
  • Comprehensive Test Coverage: Added new, dedicated test cases to mediafile_repository_test.go. These tests validate the correct behavior of the recently_added sort option under both scenarios: when RecentlyAddedByModTime is enabled (sorting by updated_at) and when it is disabled (sorting by created_at).
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

  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.

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 implements RecentlyAddedByModTime support for tracks. The changes are well-structured across the backend and frontend. My review includes suggestions to improve the robustness of the SQL query by qualifying column names and to enhance the tests to properly validate the new sorting logic.

Signed-off-by: Deluan <deluan@navidrome.org>
@deluan deluan changed the title fix: implement RecentlyAddedByModTime support for tracks (#4046) feat: implement RecentlyAddedByModTime support for tracks (#4046) Jun 30, 2025
@deluan deluan merged commit e3aec6d into master Jun 30, 2025
35 checks passed
@deluan deluan deleted the fix/recently-added-mediafiles branch June 30, 2025 13:14
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.

[Bug]: Recently added using date modified only works for albums and not tracks
1 participant