From 751b19c7b1b2fdc279cb66b25bbea0ff7e847903 Mon Sep 17 00:00:00 2001 From: Broque Thomas <26755000+Nezreka@users.noreply.github.com> Date: Sat, 25 Apr 2026 08:31:30 -0700 Subject: [PATCH] Preserve api_track_count across Plex ratingKey rekeys MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reported by kettui on PR #374 review: > api_track_count is not copied during the ratingKey migration, so > the cache disappears when an album row is rekeyed. Add it to > enrichment_cols or the next completeness scan will fall back to > live API lookups again. When Plex changes an album's ratingKey (after a library rescan), the sync code rekeys the album row by inserting a new row at the new ID and copying enrichment columns from the old row. The list of columns to copy did not include `api_track_count`, so the cached authoritative track count was lost on rekey — and the next completeness scan would hit the fallback path that calls back out to the metadata source's API. Defeats the cache. Added `api_track_count` to the album-level `enrichment_cols` at `music_database.py:4724`. The artist-level lists at lines 4238 and 4554 don't need updating — those are for artist rekeys and don't carry album-scoped fields. No new test — existing migration code has no test infrastructure and writing a Plex-mocked one is larger than this fix. Cin will say if he wants test coverage in his next review pass. Credit: kettui — PR #374 review comment that flagged the missing column in the rekey allowlist. --- database/music_database.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/database/music_database.py b/database/music_database.py index 22eb7625..ab014696 100644 --- a/database/music_database.py +++ b/database/music_database.py @@ -4728,6 +4728,10 @@ class MusicDatabase: 'audiodb_id', 'audiodb_match_status', 'audiodb_last_attempted', 'style', 'mood', 'label', 'explicit', 'record_type', 'deezer_id', 'deezer_match_status', 'deezer_last_attempted', + # api_track_count is metadata-source-derived enrichment cache; + # losing it on a ratingKey rekey would force the next + # completeness scan back to live API lookups (kettui PR #374). + 'api_track_count', ] # Read enrichment data from old album