Rehydrate cached UserData after reattachment (#16071)
This commit is contained in:
@@ -755,16 +755,30 @@ public sealed class BaseItemRepository
|
|||||||
|
|
||||||
await using (dbContext.ConfigureAwait(false))
|
await using (dbContext.ConfigureAwait(false))
|
||||||
{
|
{
|
||||||
var userKeys = item.GetUserDataKeys().ToArray();
|
var transaction = await dbContext.Database.BeginTransactionAsync(cancellationToken).ConfigureAwait(false);
|
||||||
var retentionDate = (DateTime?)null;
|
await using (transaction.ConfigureAwait(false))
|
||||||
await dbContext.UserData
|
{
|
||||||
.Where(e => e.ItemId == PlaceholderId)
|
var userKeys = item.GetUserDataKeys().ToArray();
|
||||||
.Where(e => userKeys.Contains(e.CustomDataKey))
|
var retentionDate = (DateTime?)null;
|
||||||
.ExecuteUpdateAsync(
|
|
||||||
e => e
|
await dbContext.UserData
|
||||||
.SetProperty(f => f.ItemId, item.Id)
|
.Where(e => e.ItemId == PlaceholderId)
|
||||||
.SetProperty(f => f.RetentionDate, retentionDate),
|
.Where(e => userKeys.Contains(e.CustomDataKey))
|
||||||
cancellationToken).ConfigureAwait(false);
|
.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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user