Preserve api_track_count across Plex ratingKey rekeys

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.
pull/374/head
Broque Thomas 1 month ago
parent 6c90d68de3
commit 751b19c7b1

@ -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

Loading…
Cancel
Save