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
|
|
@ -388,13 +388,23 @@ whose file was replaced looks post-coverage and is promoted into the
|
|||
**confident** reclaim pool — the one pool that is supposed to be trustworthy. The
|
||||
new-arrival grace is affected the same way in reverse.
|
||||
|
||||
**What MediaShelf does about it.** A completed play is proof the item already
|
||||
existed, so the first play is a lower bound on the true add date:
|
||||
**What MediaShelf does about it.** A view is proof the item already existed, so
|
||||
the earliest view is a lower bound on the true add date. Two independent
|
||||
witnesses, and both are needed:
|
||||
|
||||
```
|
||||
added_at = MIN(provider_added_at, first_watched_at)
|
||||
added_at = MIN(provider_added_at, first_watched_at, provider_last_viewed_at)
|
||||
```
|
||||
|
||||
`first_watched_at` is MediaShelf's first completed Tautulli play — precise, but
|
||||
only inside the history window. `provider_last_viewed_at` is Plex's own
|
||||
`lastViewedAt`, which reaches back as far as the server does.
|
||||
|
||||
The first version of this correction used Tautulli alone and **fired zero times
|
||||
on the live library**, because the wrong dates are overwhelmingly older than the
|
||||
2025-03 history window. Plex's `lastViewedAt` is the field that actually carries
|
||||
the evidence, and it was being parsed and discarded.
|
||||
|
||||
`provider_added_at` keeps Plex's raw value, `added_at_source` records which
|
||||
applied, and the UI explains the substitution on any corrected row rather than
|
||||
silently showing a different date than Plex does. Items nobody ever watched keep
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue