mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-12-26 10:44:50 +03:00
Add multiple options for internal locking (#14047)
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user