Skip to content

The Free Software Media System - Server Backend & API

Merge branch 'master' into feature/DatabaseRefactor

JPVenson850f1c79f131
diff --cc Jellyfin.Server/Program.cs
index d0f2bafb4e,7e50100b09..d8684f6da7
--- a/Jellyfin.Server/Program.cs
+++ b/Jellyfin.Server/Program.cs
@@@ -156,9 -162,9 +163,9 @@@ namespace Jellyfin.Serve
.Build();
// Re-use the host service provider in the app host since ASP.NET doesn't allow a custom service collection.
- appHost.ServiceProvider = host.Services;
+ appHost.ServiceProvider = _jellyfinHost.Services;
- await appHost.InitializeServices().ConfigureAwait(false);
+ await appHost.InitializeServices(startupConfig).ConfigureAwait(false);
Migrations.MigrationRunner.Run(appHost, _loggerFactory);
try
@@@ -195,15 -204,27 +205,16 @@@
// Don't throw additional exception if startup failed.
if (appHost.ServiceProvider is not null)
{
- var isSqlite = false;
_logger.LogInformation("Running query planner optimizations in the database... This might take a while");
- // Run before disposing the application
- var context = await appHost.ServiceProvider.GetRequiredService<IDbContextFactory<JellyfinDbContext>>().CreateDbContextAsync().ConfigureAwait(false);
- await using (context.ConfigureAwait(false))
- {
- if (context.Database.IsSqlite())
- {
- isSqlite = true;
- await context.Database.ExecuteSqlRawAsync("PRAGMA optimize").ConfigureAwait(false);
- }
- }
- if (isSqlite)
- {
- SqliteConnection.ClearAllPools();
- }
+ var databaseProvider = appHost.ServiceProvider.GetRequiredService<IJellyfinDatabaseProvider>();
+ using var shutdownSource = new CancellationTokenSource();
+ shutdownSource.CancelAfter((int)TimeSpan.FromSeconds(60).TotalMicroseconds);
+ await databaseProvider.RunShutdownTask(shutdownSource.Token).ConfigureAwait(false);
}
- host?.Dispose();
+ _appHost = null;
+ _jellyfinHost?.Dispose();
}
}