diff options
| author | martimarkov <martimarkov@users.noreply.github.com> | 2026-10-05 19:19:03 -0400 |
|---|---|---|
| committer | Cody Robibero <cody@robibe.ro> | 2026-10-05 19:19:03 -0400 |
| commit | a6cc1c196c08a0009898a14adcb38390ec948825 (patch) | |
| tree | 0e2df51b5343ec72b39e4d0a5e6f55ad4421e3e6 | |
| parent | 018406ac75f3b6d43669dedfd71324cd9dc3fc30 (diff) | |
Backport pull request #18269 from jellyfin/release-12.z
Dispose the database context in DeleteTrickplayDataAsync
Original-merge: d9b70fa662d0e50f0c5fd243c13014aca126b53e
Merged-by: crobibero <cody@robibe.ro>
Backported-by: Cody Robibero <cody@robibe.ro>
| -rw-r--r-- | Jellyfin.Server.Implementations/Trickplay/TrickplayManager.cs | 5 | ||||
| -rw-r--r-- | tests/Jellyfin.Server.Implementations.Tests/Trickplay/TrickplayManagerTests.cs | 47 |
2 files changed, 51 insertions, 1 deletions
diff --git a/Jellyfin.Server.Implementations/Trickplay/TrickplayManager.cs b/Jellyfin.Server.Implementations/Trickplay/TrickplayManager.cs index 40a153c8ed..3c1164bffe 100644 --- a/Jellyfin.Server.Implementations/Trickplay/TrickplayManager.cs +++ b/Jellyfin.Server.Implementations/Trickplay/TrickplayManager.cs @@ -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 /> diff --git a/tests/Jellyfin.Server.Implementations.Tests/Trickplay/TrickplayManagerTests.cs b/tests/Jellyfin.Server.Implementations.Tests/Trickplay/TrickplayManagerTests.cs new file mode 100644 index 0000000000..fa33806dcc --- /dev/null +++ b/tests/Jellyfin.Server.Implementations.Tests/Trickplay/TrickplayManagerTests.cs @@ -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); + } +} |
