diff options
| author | JPVenson <github@jpb.email> | 2025-06-04 00:15:22 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-03 15:15:22 -0600 |
| commit | a1d72deba2cb22006af5e286cc3bb23203ec727f (patch) | |
| tree | 2f8e29c398dd12454bb23b17b6e6ad7a38dbe6aa /Jellyfin.Server.Implementations/Extensions/ServiceCollectionExtensions.cs | |
| parent | 9456d7168f64a30513922f8077f0a61c8b751d2e (diff) | |
Add multiple options for internal locking (#14047)
Diffstat (limited to 'Jellyfin.Server.Implementations/Extensions/ServiceCollectionExtensions.cs')
| -rw-r--r-- | Jellyfin.Server.Implementations/Extensions/ServiceCollectionExtensions.cs | 17 |
1 files changed, 17 insertions, 0 deletions
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<IJellyfinDatabaseProvider>(providerFactory!); + switch (efCoreConfiguration.LockingBehavior) + { + case DatabaseLockingBehaviorTypes.NoLock: + serviceCollection.AddSingleton<IEntityFrameworkCoreLockingBehavior, NoLockBehavior>(); + break; + case DatabaseLockingBehaviorTypes.Pessimistic: + serviceCollection.AddSingleton<IEntityFrameworkCoreLockingBehavior, PessimisticLockBehavior>(); + break; + case DatabaseLockingBehaviorTypes.Optimistic: + serviceCollection.AddSingleton<IEntityFrameworkCoreLockingBehavior, OptimisticLockBehavior>(); + break; + } + serviceCollection.AddPooledDbContextFactory<JellyfinDbContext>((serviceProvider, opt) => { var provider = serviceProvider.GetRequiredService<IJellyfinDatabaseProvider>(); provider.Initialise(opt); + var lockingBehavior = serviceProvider.GetRequiredService<IEntityFrameworkCoreLockingBehavior>(); + lockingBehavior.Initialise(opt); }); return serviceCollection; |
