Skip to content

fix(server): improve Jellyfin watch data aggregation#2488

Merged
enoch85 merged 4 commits into
mainfrom
jellyfin-watch-userdata-fix
Mar 24, 2026
Merged

fix(server): improve Jellyfin watch data aggregation#2488
enoch85 merged 4 commits into
mainfrom
jellyfin-watch-userdata-fix

Conversation

@enoch85

@enoch85 enoch85 commented Mar 13, 2026

Copy link
Copy Markdown
Collaborator

Description & Design

This switches Jellyfin per-user item lookups to the dedicated user-data endpoint, centralizes the shared batching logic, and adds caching for favorites and total play count.

This fixes incorrect show lastViewedAt aggregation in Jellyfin and reduces repeated per-user API work in the same adapter path.

Related issue

Fixes #2486
Fixes #2427

Checklist

  • I have performed a self-review of my code
  • I have linted and formatted my code
  • New and existing unit tests pass locally with my changes

How to test

  1. Run yarn format.
  2. Run yarn test.
  3. Verify a Jellyfin show rule using lastViewedAt picks up the latest watched episode date.

@enoch85 enoch85 requested a review from ydkmlt84 as a code owner March 13, 2026 16:42
enoch85 added a commit that referenced this pull request Mar 13, 2026
PR #2488 - fix(server): improve Jellyfin watch data aggregation
- Improve watch history aggregation with per-user UserData lookups
- Honor Jellyfin played threshold (MaxResumePct) for watch status
- Add getItemFavoritedBy and getTotalPlayCount methods
- Address review feedback with debug logging and fallback handling
@enoch85 enoch85 self-assigned this Mar 13, 2026
@enoch85

enoch85 commented Mar 13, 2026

Copy link
Copy Markdown
Collaborator Author

Tested and works! Manual validation against Jellyfin looks good:

  • Unwatched shows still return lastViewedAt = null and are skipped by BEFORE/AFTER comparisons.
  • Watched shows are now matched correctly by show-level Jellyfin.lastViewedAt rules, which confirms episode watch data is being aggregated into the show value.

Cache

The Jellyfin watch-data fix appears to work, and the second evaluation produced no repeated Jellyfin user-data activity within the cache TTL.

enoch85 added 3 commits March 21, 2026 19:03
The dedicated /UserItems/{itemId}/UserData endpoint does not reliably
return per-user data when authenticating with an API key on all Jellyfin
versions, causing viewCount=0 and lastViewedAt=null for watched items.

Revert to the proven getItems query with enableUserData=true while
keeping all other PR #2488 improvements (centralized batching, caching).

Fixes #2509
@enoch85 enoch85 force-pushed the jellyfin-watch-userdata-fix branch from 050c19e to 1ea1622 Compare March 21, 2026 19:04
enoch85 added a commit that referenced this pull request Mar 21, 2026
PR #2488 - fix(server): revert Jellyfin getItemUserData to use getItems endpoint
- Revert per-user data fetching from dedicated /UserItems/{itemId}/UserData endpoint back to getItems with enableUserData=true
- The dedicated endpoint does not reliably return per-user data with API key auth on all Jellyfin versions
- Fixes viewCount=0 and lastViewedAt=null regression reported in #2509
- Update test mocks to match reverted getItems call signature
@enoch85 enoch85 merged commit 63f0abb into main Mar 24, 2026
12 checks passed
@enoch85 enoch85 deleted the jellyfin-watch-userdata-fix branch March 24, 2026 20:02
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 3.2.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

enoch85 added a commit that referenced this pull request Apr 9, 2026
Extract mapUsersBatched as the single per-user fan-out primitive.
getAllUserItemData (introduced in #2488 to centralise watch history /
favorited-by / play-count aggregation) and the new
getDescendantEpisodeWatchers now both route through it, removing the
duplicated batching loop from the previous commit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

jellyfin lastWatched is null on unwatched items Add result caching to getItemFavoritedBy and getTotalPlayCount

1 participant