Use Plex's lastViewedAt for the date correction, not just Tautulli
The correction shipped in the previous commit fired zero times on the live library. It compared Plex's addedAt against MediaShelf's first completed Tautulli play, but Tautulli history only starts 2025-03-08 and the wrong dates are overwhelmingly older than that. The evidence that proved the bug in the first place was Plex's own lastViewedAt - which the provider parsed and then dropped on the floor. Now stored as provider_last_viewed_at and folded into the bound: added_at = MIN(provider_added_at, first_watched_at, provider_last_viewed_at). Seasons also get their own provider_added_at (MIN over episodes), without which their added_at_source could never be computed. Fixture gains the case that actually failed: added last week, last viewed 1500 days ago, no Tautulli history at all - so only lastViewedAt carries it. Also tightened test_correction_leaves_unwatched_items_alone, which defined "unwatched" as watch_count=0 and so wrongly expected an item with Plex view evidence to be left alone. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GVbG48GAXfCZatcmX123Ra
This commit is contained in:
parent
e819548ff2
commit
edbb6f088f
6 changed files with 134 additions and 36 deletions
13
mediashelf/migrations/003_provider_last_viewed.sql
Normal file
13
mediashelf/migrations/003_provider_last_viewed.sql
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
-- The added_at correction added in 002 could only use Tautulli's history, which
|
||||
-- starts 2025-03-08. But the evidence that proved Plex's addedAt wrong is Plex's
|
||||
-- own lastViewedAt, which reaches back years further — 2001: A Space Odyssey
|
||||
-- reports added 2026-07-31 and last watched 2017-08-26.
|
||||
--
|
||||
-- That field was parsed by the provider and then dropped on the floor, so the
|
||||
-- correction fired zero times on the live library. Store it.
|
||||
--
|
||||
-- Seasons also need a provider_added_at of their own (the MIN over their
|
||||
-- episodes), or their added_at_source can never be computed.
|
||||
|
||||
ALTER TABLE media_item ADD COLUMN provider_last_viewed_at INTEGER;
|
||||
ALTER TABLE episode ADD COLUMN provider_last_viewed_at INTEGER;
|
||||
Loading…
Add table
Add a link
Reference in a new issue