aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Sundermann <stephansundermann@gmail.com>2025-07-18 01:19:26 +0200
committerGitHub <noreply@github.com>2025-07-17 17:19:26 -0600
commit2ad37fe021ca50b9309ab9b04dc8d02282ea1acd (patch)
tree96a08bf6d190881dea6a7f4f5097db4c1ca47244
parentfd5205a6eb05232ee4e880cf733ab8ede3598008 (diff)
Ensure UserData stays unique on delete (#14475)
-rw-r--r--Jellyfin.Server.Implementations/Item/BaseItemRepository.cs14
1 files changed, 14 insertions, 0 deletions
diff --git a/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs b/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs
index a1e3a7bc4..1fa64a5e8 100644
--- a/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs
+++ b/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs
@@ -110,6 +110,20 @@ public sealed class BaseItemRepository
using var transaction = context.Database.BeginTransaction();
var date = (DateTime?)DateTime.UtcNow;
+
+ // Remove any UserData entries for the placeholder item that would conflict with the UserData
+ // being detached from the item being deleted. This is necessary because, during an update,
+ // UserData may be reattached to a new entry, but some entries can be left behind.
+ // Ensures there are no duplicate UserId/CustomDataKey combinations for the placeholder.
+ context.UserData
+ .Join(
+ context.UserData.Where(e => e.ItemId == id),
+ placeholder => new { placeholder.UserId, placeholder.CustomDataKey },
+ userData => new { userData.UserId, userData.CustomDataKey },
+ (placeholder, userData) => placeholder)
+ .Where(e => e.ItemId == PlaceholderId)
+ .ExecuteDelete();
+
// Detach all user watch data
context.UserData.Where(e => e.ItemId == id)
.ExecuteUpdate(e => e