Skip to content

fix: ensure full scan refreshes all artist stats #4252

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 2 commits into from
Jun 23, 2025

Conversation

deluan
Copy link
Member

@deluan deluan commented Jun 22, 2025

Problem

After PR #4059, full scans were not forcing a refresh of all artists. During a full scan, only artists with recently updated media files would have their stats refreshed, leaving other artists with potentially stale statistics.

Solution

This PR implements a clean solution that ensures all artist stats are refreshed during full scans:

Changes Made

  1. Set changesDetected = true for full scans - This ensures all maintenance operations (GC, library stats refresh, etc.) run automatically during full scans

  2. Add allArtists parameter to RefreshStats() - Makes the intent explicit:

    • When allArtists = true: Refresh stats for all artists
    • When allArtists = false: Refresh stats for touched artists only (original behavior)
  3. Pass fullScan state to RefreshStats - The scanner now passes state.fullScan as the allArtists parameter

  4. Update mock repository - Updated test mock to match the new interface

Benefits

  • Explicit intent: The allArtists parameter makes it crystal clear what the method does
  • Automatic maintenance: All maintenance operations run during full scans without additional conditional checks
  • Simple & maintainable: Single point of control, no need for dual conditions throughout the codebase
  • Future-proof: New maintenance operations will automatically work with full scans

Testing

  • All existing tests pass
  • Code is properly formatted and linted
  • No breaking changes to existing functionality

Related Issues

Fixes #4246
Related to PR #4059

Behavior

  • Full Scan: changesDetected = true → All maintenance runs → RefreshStats(true) → Refreshes all artists
  • Quick Scan: changesDetected set only when actual changes detected → RefreshStats(false) → Refreshes touched artists only

@Copilot Copilot AI review requested due to automatic review settings June 22, 2025 21:10
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 resolves an issue where full library scans were not consistently refreshing all artist statistics, potentially leaving some artist data stale. It introduces a refined mechanism to ensure that during a full scan, all artist stats are updated, while maintaining the existing behavior for quick scans to only refresh stats for artists with detected changes. This change enhances data accuracy and improves the reliability of maintenance operations.

Highlights

  • Artist Stats Refresh Logic: The RefreshStats method in the ArtistRepository interface and its implementation now accepts a boolean parameter, allArtists, to explicitly control whether to refresh statistics for all artists or only those with recently updated media files.
  • Full Scan Behavior: During a full scan, the scanner now explicitly sets changesDetected to true. This ensures that all necessary maintenance operations, including artist stat refreshes, are automatically triggered, addressing the issue of stale artist statistics after a full scan.
  • Scanner Integration: The scanner's fullScan state is now directly passed to the RefreshStats method. This ensures that full scans correctly trigger a comprehensive refresh of all artist statistics, aligning with the intended behavior.
  • Testing Utilities: The mock implementation for the ArtistRepository has been updated to reflect the new RefreshStats method signature, maintaining test compatibility and ensuring proper testing of the updated logic.
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

@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 ensures that a full library scan refreshes statistics for all artists by introducing an explicit allArtists parameter to RefreshStats, setting changesDetected to true for full scans, and updating implementations and tests accordingly.

  • Set changesDetected = true during full scans so all maintenance tasks run
  • Added allArtists parameter to RefreshStats and updated calls in scanner
  • Updated the repository interface, persistence implementation, and mock repo to support the new signature

Reviewed Changes

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

File Description
tests/mock_artist_repo.go Added RefreshStats(allArtists bool) and RefreshPlayCounts to the mock repo
scanner/scanner.go Initialized changesDetected atomically and passed fullScan to RefreshStats
persistence/artist_repository.go Modified RefreshStats to accept allArtists and handle both full and partial flows
model/artist.go Updated the ArtistRepository interface to include the new allArtists parameter
Comments suppressed due to low confidence (3)

persistence/artist_repository.go:300

  • [nitpick] The variable name touchedArtistsQuerySQL is misleading in the full-scan branch since it actually fetches all artist IDs. Consider renaming it to querySQL or splitting it into separate variables like allArtistsQuerySQL and touchedArtistsQuerySQL for clarity.
		touchedArtistsQuerySQL := `SELECT DISTINCT id FROM artist WHERE id <> ''`

scanner/scanner.go:162

  • There are no existing tests to verify that RefreshStats is called with allArtists=true when fullScan=true. Add a unit test for scanAll or runRefreshStats to cover this new behavior.
		stats, err := s.ds.Artist(ctx).RefreshStats(state.fullScan)

scanner/scanner.go:48

  • Moving the startTime declaration before the library fetch changes the duration measurement to include the GetAll() call. If the intent was to measure only the scan phase, consider moving it back to just before the main scan loop.
	startTime := time.Now()

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 fixes an issue where a full scan didn't refresh all artist statistics. The changes are logical and well-described. The introduction of the allArtists parameter in RefreshStats and forcing changesDetected for full scans are clean solutions. I've made suggestions to improve variable naming for better code clarity and maintainability.

deluan added 2 commits June 23, 2025 13:15
After PR #4059, full scans were not forcing a refresh of all artists.
This change ensures that during full scans, all artist stats are refreshed
instead of only those with recently updated media files.

Changes:
- Set changesDetected=true at start of full scans to ensure maintenance operations run
- Add allArtists parameter to RefreshStats() method
- Pass fullScan state to RefreshStats to control refresh scope
- Update mock repository to match new interface

Fixes #4246
Related to PR #4059
Signed-off-by: Deluan <deluan@navidrome.org>
@deluan deluan force-pushed the fix-full-scan-artist-refresh branch from 2e55fd1 to 9aad72b Compare June 23, 2025 17:15
@deluan deluan merged commit e5e2d86 into master Jun 23, 2025
35 checks passed
@deluan deluan deleted the fix-full-scan-artist-refresh branch June 23, 2025 17:26
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]: Album Artists and Artists Stats Not Updating After Upgrade to 0.56.1
1 participant