Merge pull request 'Add placeholder item handling and related unit test for deletion' (#2) from pgsql_testing_branch into main

Reviewed-on: #2
This commit was merged in pull request #2.
This commit is contained in:
2026-04-13 19:10:24 +00:00
2 changed files with 153 additions and 0 deletions
@@ -63,6 +63,9 @@ public sealed class BaseItemRepository
/// </summary>
public static readonly Guid PlaceholderId = Guid.Parse("00000000-0000-0000-0000-000000000001");
private const string PlaceholderType = "PLACEHOLDER";
private const string PlaceholderName = "This is a placeholder item for UserData that has been detacted from its original item";
/// <summary>
/// This holds all the types in the running assemblies
/// so that we can de-serialize properly when we don't have strong types.
@@ -129,6 +132,8 @@ public sealed class BaseItemRepository
{
var date = (DateTime?)DateTime.UtcNow;
await EnsurePlaceholderItemAsync(context, cancellationToken).ConfigureAwait(false);
var relatedItems = ids.SelectMany(f => TraverseHirachyDown(f, context)).ToArray();
// Remove any UserData entries for the placeholder item that would conflict with the UserData
@@ -196,6 +201,38 @@ public sealed class BaseItemRepository
}
}
private async Task EnsurePlaceholderItemAsync(JellyfinDbContext context, CancellationToken cancellationToken)
{
if (await context.BaseItems.AnyAsync(e => e.Id == PlaceholderId, cancellationToken).ConfigureAwait(false))
{
return;
}
var placeholder = new BaseItemEntity
{
Id = PlaceholderId,
Type = PlaceholderType,
Name = PlaceholderName
};
await context.BaseItems.AddAsync(placeholder, cancellationToken).ConfigureAwait(false);
try
{
await context.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
_logger.LogWarning("The detached UserData placeholder item was missing and has been recreated.");
}
catch (DbUpdateException)
{
context.Entry(placeholder).State = EntityState.Detached;
if (!await context.BaseItems.AnyAsync(e => e.Id == PlaceholderId, cancellationToken).ConfigureAwait(false))
{
throw;
}
}
}
/// <inheritdoc />
public void UpdateInheritedValues()
{