aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server.Implementations/Extensions/ServiceCollectionExtensions.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Jellyfin.Server.Implementations/Extensions/ServiceCollectionExtensions.cs')
-rw-r--r--Jellyfin.Server.Implementations/Extensions/ServiceCollectionExtensions.cs17
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;