From a1d72deba2cb22006af5e286cc3bb23203ec727f Mon Sep 17 00:00:00 2001 From: JPVenson Date: Wed, 4 Jun 2025 00:15:22 +0300 Subject: Add multiple options for internal locking (#14047) --- .../Extensions/ServiceCollectionExtensions.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'Jellyfin.Server.Implementations/Extensions/ServiceCollectionExtensions.cs') diff --git a/Jellyfin.Server.Implementations/Extensions/ServiceCollectionExtensions.cs b/Jellyfin.Server.Implementations/Extensions/ServiceCollectionExtensions.cs index fbbb5bca7..392a8de2c 100644 --- a/Jellyfin.Server.Implementations/Extensions/ServiceCollectionExtensions.cs +++ b/Jellyfin.Server.Implementations/Extensions/ServiceCollectionExtensions.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Reflection; using Jellyfin.Database.Implementations; using Jellyfin.Database.Implementations.DbConfiguration; +using Jellyfin.Database.Implementations.Locking; using Jellyfin.Database.Providers.Sqlite; using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Configuration; @@ -73,6 +74,7 @@ public static class ServiceCollectionExtensions efCoreConfiguration = new DatabaseConfigurationOptions() { DatabaseType = "Jellyfin-SQLite", + LockingBehavior = DatabaseLockingBehaviorTypes.NoLock }; configurationManager.SaveConfiguration("database", efCoreConfiguration); } @@ -85,10 +87,25 @@ public static class ServiceCollectionExtensions serviceCollection.AddSingleton(providerFactory!); + switch (efCoreConfiguration.LockingBehavior) + { + case DatabaseLockingBehaviorTypes.NoLock: + serviceCollection.AddSingleton(); + break; + case DatabaseLockingBehaviorTypes.Pessimistic: + serviceCollection.AddSingleton(); + break; + case DatabaseLockingBehaviorTypes.Optimistic: + serviceCollection.AddSingleton(); + break; + } + serviceCollection.AddPooledDbContextFactory((serviceProvider, opt) => { var provider = serviceProvider.GetRequiredService(); provider.Initialise(opt); + var lockingBehavior = serviceProvider.GetRequiredService(); + lockingBehavior.Initialise(opt); }); return serviceCollection; -- cgit v1.2.3