Merge pull request #18269 from mm-workspace/dispose-trickplay-delete-context

Dispose the database context in DeleteTrickplayDataAsync
This commit is contained in:
Cody Robibero authored and GitHub committed 2026-10-04 06:54:15 -06:00
commit d9b70fa662
2 files changed
+51 -1

No files matched your search

@@ -731,7 +731,10 @@ public partial class TrickplayManager : ITrickplayManager
public async Task DeleteTrickplayDataAsync(Guid itemId, CancellationToken cancellationToken)
{
var dbContext = await _dbProvider.CreateDbContextAsync(cancellationToken).ConfigureAwait(false);
await dbContext.TrickplayInfos.Where(i => i.ItemId.Equals(itemId)).ExecuteDeleteAsync(cancellationToken).ConfigureAwait(false);
await using (dbContext.ConfigureAwait(false))
{
await dbContext.TrickplayInfos.Where(i => i.ItemId.Equals(itemId)).ExecuteDeleteAsync(cancellationToken).ConfigureAwait(false);
}
}
/// <inheritdoc />
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Database.Implementations;
using Jellyfin.Server.Implementations.Tests.Item;
using Jellyfin.Server.Implementations.Trickplay;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using Xunit;
namespace Jellyfin.Server.Implementations.Tests.Trickplay;
public sealed class TrickplayManagerTests : SqliteDbTestFixture
{
[Fact]
public async Task DeleteTrickplayDataAsync_DisposesDbContext()
{
var contexts = new List<JellyfinDbContext>();
var factory = new Mock<IDbContextFactory<JellyfinDbContext>>();
factory.Setup(f => f.CreateDbContextAsync(It.IsAny<CancellationToken>()))
.ReturnsAsync(() =>
{
var context = CreateDbContext();
contexts.Add(context);
return context;
});
// Only the database context factory is used when deleting trickplay data.
var trickplayManager = new TrickplayManager(
NullLogger<TrickplayManager>.Instance,
null!,
null!,
null!,
null!,
null!,
factory.Object,
null!,
null!);
await trickplayManager.DeleteTrickplayDataAsync(Guid.NewGuid(), CancellationToken.None);
var context = Assert.Single(contexts);
Assert.Throws<ObjectDisposedException>(() => context.Model);
}
}