The Free Software Media System - Server Backend & API
Backport pull request #16071 from jellyfin/release-10.11.z
MarcoCoreDuo6d34f605a357
diff --git a/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs b/Jellyfin.Server.Implementations/Item/BaseItemRepository.csindex 43a3cdf78f..338544ab96 100644--- a/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs+++ b/Jellyfin.Server.Implementations/Item/BaseItemRepository.cs@@ -762,16 +762,30 @@ public sealed class BaseItemRepositoryawait using (dbContext.ConfigureAwait(false)){- var userKeys = item.GetUserDataKeys().ToArray();- var retentionDate = (DateTime?)null;- await dbContext.UserData- .Where(e => e.ItemId == PlaceholderId)- .Where(e => userKeys.Contains(e.CustomDataKey))- .ExecuteUpdateAsync(- e => e- .SetProperty(f => f.ItemId, item.Id)- .SetProperty(f => f.RetentionDate, retentionDate),- cancellationToken).ConfigureAwait(false);+ var transaction = await dbContext.Database.BeginTransactionAsync(cancellationToken).ConfigureAwait(false);+ await using (transaction.ConfigureAwait(false))+ {+ var userKeys = item.GetUserDataKeys().ToArray();+ var retentionDate = (DateTime?)null;++ await dbContext.UserData+ .Where(e => e.ItemId == PlaceholderId)+ .Where(e => userKeys.Contains(e.CustomDataKey))+ .ExecuteUpdateAsync(+ e => e+ .SetProperty(f => f.ItemId, item.Id)+ .SetProperty(f => f.RetentionDate, retentionDate),+ cancellationToken).ConfigureAwait(false);++ // Rehydrate the cached userdata+ item.UserData = await dbContext.UserData+ .AsNoTracking()+ .Where(e => e.ItemId == item.Id)+ .ToArrayAsync(cancellationToken)+ .ConfigureAwait(false);++ await transaction.CommitAsync(cancellationToken).ConfigureAwait(false);+ }}}