Commit Graph

84 Commits

Author SHA1 Message Date
Paolo Antinori 5d580abb08 fix: avoid NRE when sorting by user-dependent keys without a user
A query sorted by a user-dependent key (PlayCount, IsFavoriteOrLiked,
DatePlayed, IsPlayed, IsUnplayed) but carrying no User caused a
NullReferenceException inside UserDataManager.GetUserData, surfacing as
"Failed to compare two elements in the array" (InvalidOperationException
wrapping the NRE from the LINQ sort) and 500-ing the /Items request.

Root cause: LibraryManager.GetComparer assigned comparer.User = user
without a null guard, so PlayCountComparer.GetValue called
UserDataManager.GetUserData(null, item), dereferencing user.Id.

Two-part fix:
- LibraryManager.GetComparer: when user is null and the sort key requires a
  user (IUserBaseItemComparer), substitute the SortName comparer so the
  result stays deterministic instead of 500-ing. SortName is the project's
  canonical tiebreaker (ItemsController injects it for album-by-artist).
- UserDataManager.GetUserData: ArgumentNullException.ThrowIfNull(user) as
  defense in depth (matches the existing guards on the SaveUserData
  overloads in the same file). On master this overload was rewritten to use
  ResolveUserDataRow, so the NRE dereferences user.Id rather than
  user.InternalId as on the release branch — same bug, different line.

Also fixes DateLastMediaAddedComparer being statically mis-tagged as
IUserBaseItemComparer: its GetDate is static and never reads User, so it
does not need one. Without this, the SortName fallback above would wrongly
engage for DateLastContentAdded on anonymous queries (returning SortName
order instead of date order). Re-tagged to IBaseItemComparer and dropped the
unused User/UserManager/UserDataManager properties.

Tests:
- UserDataManagerTests.GetUserData_NullUser_ThrowsArgumentNullException:
  reproduces the crash (NRE -> now ArgumentNullException). Added to master's
  existing UserDataManagerTests.
- LibraryManagerSortTests.Sort_UserDependentKey_NullUser_FallsBackToSortNameWithoutThrowing:
  Sort with a user-dependent key + null user no longer throws and returns
  items ordered by the SortName fallback (direction preserved).
- LibraryManagerSortTests.Sort_DateLastContentAdded_NullUser_OrdersByDateNotSortName:
  guards that DateLastContentAdded still sorts by date with no user (fixture
  chosen so date-desc and SortName-desc disagree, so a revert is caught).

Full Jellyfin.Server.Implementations.Tests suite: 642 passed, 0 failed.

Fixes #17393
2026-07-22 07:43:58 +02:00
Cody Robibero bea016c962 Merge pull request #17320 from TaterTechStudios/fix/item-correct-selector
Fix: Fetch the correct row matching the most up to date file
2026-07-20 19:57:28 -04:00
Shadowghost cdf7ce0fc4 Fix user data batch query perf 2026-07-16 14:21:03 +02:00
Jordan Rushing 3f96790904 Move GetUserDataBatch to use ResolveUserDataRow when item.UserData isn't preloaded 2026-07-15 16:21:42 -05:00
Jordan Rushing fcce108948 Fix: Fetch the correct row matching the most up to date file 2026-07-13 15:40:40 -05:00
Shadowghost 38f1d9749e Fix review comments 2026-07-02 08:49:11 +02:00
Shadowghost 0fb042b740 Surface the played version for resume 2026-06-19 21:51:57 +02:00
Shadowghost 0aeee8233b Fix performance 2026-06-12 08:35:30 +02:00
Shadowghost 0874a26131 Coalesce alternate-version progress onto primary in resume filter 2026-06-09 23:23:03 +02:00
Shadowghost c242533f4e Add version-aware playback tracking 2026-06-07 23:06:14 +02:00
Shadowghost f806ae4018 Fix too many SQL variables error on large libraries 2026-04-19 10:27:47 +02:00
Shadowghost d3d4d37e82 Simplify UserDataManager and remove unused private methods
Removes unused private GetUserData and GetUserDataInternal methods.
Moves GetUserDataBatch to be an abstract interface method rather than
having a default implementation for clarity.
2026-01-18 19:45:39 +01:00
JPVenson 98f5e21bb8 Fix groupings not applied (#14826) 2025-09-22 15:31:21 -06:00
JPVenson a0b3e2b071 Optimize internal querying of UserData, other fixes (#14795) 2025-09-16 13:08:04 -06:00
theguymadmax 986a509955 Add 1-second tolerance to resume playback completion check (#14774) 2025-09-11 15:24:23 -06:00
Cody Robibero 88ceaa39b0 Implement limiting caches (#13605)
* Implement basic expiring cache for LibraryManager

* Add expiring cache to more places

* Rider why

* Make DirectoryService caches static

* Use FastConcurrentLru

* Reduce default cache size

* Simplify DirectoryService caches

* Make directory service cache size at least 128
2025-03-27 18:16:54 -06:00
JPVenson 42bdb22bfb Fixed namespaces 2025-03-25 16:45:00 +01:00
JPVenson 160020c551 WIP fixed namespaces 2025-03-25 15:30:22 +00:00
JPVenson 2f306358c0 applied review comments 2025-01-18 16:17:26 +00:00
JPVenson 96e4d8ca78 worsen comment 2025-01-17 19:19:24 +00:00
JPVenson b33810534b Applied review comments 2025-01-15 20:12:41 +00:00
JPVenson 427359deee Merge branch 'master' into feature/EFUserData 2024-11-17 01:23:26 +01:00
Bond-009 ceb850c770 Update projects to .NET 9 (#13023) 2024-11-16 10:11:01 -07:00
JPVenson 37129f7952 Fixed Transaction for Userdata 2024-11-14 21:48:21 +00:00
JPVenson d3174b5171 Fixed userdata lookup 2024-11-12 16:14:17 +00:00
JPVenson 508b27f156 Fixed Duplicate returns on grouping
Fixed UserDataKey not stored
2024-11-11 17:39:50 +00:00
JPVenson 2d4f7f725f Fixed TopParent not beeing migrated 2024-11-11 00:27:30 +00:00
JPVenson c2a0dfb1e5 Reodered Context creation 2024-10-22 10:53:39 +00:00
JPVenson e331dc35ac Fixed tests 2024-10-20 11:04:54 +00:00
JPVenson 10a2a316a4 i have too much time.
Refactored BaseItem and UserData relation
2024-10-20 10:11:24 +00:00
JPVenson d0b4b2ddb3 Migrated UserData from library sqlite db to jellyfin.db 2024-09-07 19:07:34 +00:00
Bond_009 277830855d Clean up UserDataManager
* enable nullable
* remove unused methods
* fix warnings and docs
2024-08-30 15:08:56 +02:00
ArabCoders c4013d2e10 Updated the summary and the Dto name. 2023-11-15 13:55:14 +03:00
ArabCoders 07db2025a1 Refactored the code to not use reflection. 2023-11-13 17:32:24 +03:00
ArabCoders 2a25c5a2e3 Refactored api call logic handling. 2023-11-13 15:51:06 +03:00
Bond_009 52194f56b5 Replace != null with is not null 2022-12-05 15:01:13 +01:00
Bond_009 a9a5fcde81 Use ArgumentNullException.ThrowIfNull helper method
Did a simple search/replace on the whole repo (except the RSSDP project)
This reduces LOC and should improve performance (methods containing a throw statement don't get inlined)

```
if \((\w+) == null\)
\s+\{
\s+throw new ArgumentNullException\((.*)\);
\s+\}
```

```
ArgumentNullException.ThrowIfNull($1);
```
2022-10-06 20:21:23 +02:00
Bond_009 ea8f40e84a More cleanup 2021-12-27 14:20:05 +00:00
Patrick Barron 876a902356 Fix warnings in Library 2021-10-03 21:41:22 -04:00
Bond_009 637e86478f Fix some warnings 2021-09-03 19:32:11 +02:00
Claus Vium 9f2e8063ec Merge pull request #5997 from JKI12/master
Fixes for Book Progress
2021-05-24 08:52:38 +02:00
Bond_009 7e8428e588 Enable nullable reference types for Emby.Server.Implementations 2021-05-20 22:48:53 +02:00
Jake King bc017737e6 Changed condition for readbility
- Refactored check if item is not audio book or book to be more readable
2021-05-07 10:35:03 +01:00
Jake King 3cd57cb287 Fixes for Book Progress
- Ignore Books when checking for minium progress
2021-05-06 19:50:00 +01:00
artiume 005ae80b31 Update var names 2021-04-21 07:11:14 -04:00
artiume dcd96909cd Fix Audiobook Resume
https://github.com/jellyfin/jellyfin/issues/5703
2021-04-20 19:28:18 -04:00
BaronGreenback bc1cc2d04a Remove unused using directives 2021-04-17 11:37:55 +01:00
artiume f411353c8c Update Emby.Server.Implementations/Library/UserDataManager.cs
Co-authored-by: Bond-009 <bond.009@outlook.com>
2020-12-30 09:30:02 -05:00
artiume c7cb177260 Update Emby.Server.Implementations/Library/UserDataManager.cs
Co-authored-by: Bond-009 <bond.009@outlook.com>
2020-12-30 09:12:36 -05:00
artiume 77b478c726 Update Emby.Server.Implementations/Library/UserDataManager.cs
Co-authored-by: Bond-009 <bond.009@outlook.com>
2020-12-30 09:12:13 -05:00