-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix artist stats not refreshing during quick scan and after missing file deletion #4269
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
Conversation
When a new album is added during quick scans, artists were not being marked as 'touched' due to media files having older modification times than the scan completion time. Changes: - Add 'updated_at' to artist Put() columns in scanner to ensure timestamp is set when artists are processed - Simplify RefreshStats query to check artist.updated_at directly instead of complex media file joins - Artists from new albums now properly get refreshed in later phases This fixes the issue where newly added albums would have incomplete artist information after quick scans.
…ng files Signed-off-by: Deluan <deluan@navidrome.org>
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 @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 critical data consistency issues related to artist statistics by ensuring that artist records are properly "touched" (their updated_at
timestamps updated) during library scans and after the deletion of missing files. It also refines the artist statistics refresh mechanism to more effectively utilize these timestamps, leading to more accurate and up-to-date artist information across the application.
Highlights
- Improved Artist Data Freshness during Scans: Artists created or updated during quick scans will now have their
updated_at
timestamps correctly set, ensuring they are considered for subsequentRefreshStats
operations. - Accurate Artist Stats After File Deletions: Deleting missing media files will now trigger a background refresh of artist statistics, preventing stale data for artists whose associated files have been removed.
- Simplified Artist Statistics Refresh Logic: The
RefreshStats
method's incremental query has been streamlined to directly leverage theartist.updated_at
timestamp, making the logic more robust and aligned with the new timestamp handling.
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 configure Gemini 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.
Pull Request Overview
This PR ensures artist statistics are properly refreshed by updating timestamp handling during scanning, simplifying the incremental refresh logic, and triggering a non-blocking background refresh after missing file deletions.
- Marks artists as touched during quick scans by persisting
updated_at
- Simplifies
RefreshStats
to useupdated_at > last_scan_at
- Fires off a background
RefreshStats(true)
after deleting missing files
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
scanner/phase_1_folders.go | Added "updated_at" to artistRepo.Put columns to ensure timestamps are set |
persistence/artist_repository.go | Simplified RefreshStats to query artists based on updated_at |
server/nativeapi/missing.go | Spawn a goroutine to call RefreshStats(true) in background after file deletion |
Comments suppressed due to low confidence (2)
server/nativeapi/missing.go:96
- [nitpick] Add a comment explaining that context.Background() is used intentionally to detach the refresh job from request cancellation and carry over request values.
bgCtx := request.AddValues(context.Background(), r.Context())
server/nativeapi/missing.go:95
- [nitpick] Consider limiting concurrent background RefreshStats goroutines or using a job queue to prevent multiple heavy refresh operations from running simultaneously.
go func() {
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 addresses the issue of artist statistics not refreshing correctly during quick scans and after missing file deletion. The changes include updating the artist's updated_at
field during scanning, triggering a background RefreshStats
call after deleting missing files, and simplifying the RefreshStats
query logic. The changes look good overall, but there are some critical and high severity issues that need to be addressed.
Signed-off-by: Deluan <deluan@navidrome.org>
- Add test that verifies artist statistics are correctly updated when new files are added during incremental scans - Test ensures both overall stats (AlbumCount, SongCount) and role-specific stats are properly refreshed - Validates fix for artist stats not being refreshed during quick scans when new albums are added - Uses real artist repository instead of mock to verify actual stats calculation behavior
Problem
Artist statistics were not being refreshed correctly in two scenarios:
Root Cause
The issue stemmed from the RefreshStats method relying on artist
updated_at
timestamps to determine which artists need refreshing, but:updated_at
fieldSolution
Two-part fix:
1. Scanner Fix (
scanner/phase_1_folders.go
)"updated_at"
to the list of columns when callingartistRepo.Put()
2. Missing File Deletion Fix (
server/nativeapi/missing.go
)RefreshStats(true)
call after successful missing file deletion3. RefreshStats Simplification (
persistence/artist_repository.go
)updated_at > last_scan_at
directlyKey Benefits
Files Changed
scanner/phase_1_folders.go
: Include "updated_at" in artist Put columnspersistence/artist_repository.go
: Simplified RefreshStats query logicserver/nativeapi/missing.go
: Background RefreshStats after file deletionThis ensures artist statistics are always accurate for both scanning and missing file management operations.