upgrades and wants: clear upgrades once they land, one want per item - #4
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
F14: upgrades never cleared, so they re-downloaded every 48h.
Title (Year).mkv/Show - S01E01.mkv, which carries no resolution tag. The scanner ranked that file 0 and kept the old tagged copy (Zootopia 2 2025 1080p TS,Rags.2012.720p…) as "best".GRAB_RETRY_HOURSthe hunter grabbed another copy. After sort: never lose or overwrite data when filing releases #3 those copies get quarantined instead of overwriting, so the loop now fills_failed/rather than the library, but the downloads never stop.test_movie_720p_upgrades_and_clears_when_satisfiedpasses only because it lands the upgrade under a name the sorter never produces.F14, second half: the hunter never checked that an upgrade was an upgrade.
["1080p","720p"]profile happily ranks a 720p release for a 720p-owned movie.F14, episodes:
library_episodeskept whichever of two copies the scan walked last, so upgrades flip-flopped.F19: prod still has the old title-keyed constraint.
wantedtable still hasUNIQUE(kind, series_id, season, episode, title)(confirmed earlier).F20: movie wants were never unique. Their season/episode are NULL, and SQLite treats NULLs in a UNIQUE constraint as distinct.
What changed
Scanner (
library.py)library_filesrecord (sort: never lose or overwrite data when filing releases #3), falling back to the filename. A record whose size no longer matches is ignored.library_filesrows for vanished files are pruned inside the existing mass-disappearance guard.Superseded copies are retired to
LIBRARY_ROOT/_superseded/<same relative path>, along with their sidecar subtitles. It's a rename on the same share, reversible, and outside themovies/tvshowssections, with.plexignore/.ignoremarkers in case a media server points at the root. A file is only moved when:SUPERSEDED_ACTION=keepdisables this.Hunter (
scheduler.py): upgrade wants only consider releases wherequality.is_upgrade()holds against the owned file. A cam of unknown resolution is beaten by any real source with a known resolution. When nothing qualifies, the detail line says so.Wants
wants.upsert()is the only write path for both reconcilers. It runs underBEGIN IMMEDIATEwithINSERT OR IGNORE, so select-then-insert can't race.db._migrate_wanted_key()collapses duplicates (keeping an in-flightgrabbedrow, then the most recently searched, then the oldest). It then addsux_wanted_keyon(kind, IFNULL(series_id,-1), IFNULL(season,-1), IFNULL(episode,-1)).Testing
tests/test_wants_upgrades.pyadds 24 tests. Highlights:wantedschema with duplicates, migrated.upsert()for an episode and for a movie.main, 15 of the first 17 tests fail. The two that pass pin behavior that's deliberately unchanged: unknown quality never triggers an upgrade.Deploying
_superseded/is created on first use under/library. Purge it by hand whenever you like.Not in this PR
Nine commits from API pushes; squash-merge.