diff options
| author | Bond-009 <bond.009@outlook.com> | 2022-11-13 12:22:08 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-13 12:22:08 +0100 |
| commit | 6655cf4e58285f51b612efb0bb6229f036da2591 (patch) | |
| tree | aee69ef3a65330ceb811ce2ec1102b723faa0e9e /Jellyfin.Server/Program.cs | |
| parent | 1b7500c5557996e2ab91377e5783a3802f9029a9 (diff) | |
| parent | 395efc94a771d2feb83af8d13964ca1ff6ecf476 (diff) | |
Merge pull request #8601 from cvium/add_secondlevelcaching
Diffstat (limited to 'Jellyfin.Server/Program.cs')
| -rw-r--r-- | Jellyfin.Server/Program.cs | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index a6f0b705d..7ba17ca83 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -192,6 +192,17 @@ namespace Jellyfin.Server // Re-use the web host service provider in the app host since ASP.NET doesn't allow a custom service collection. appHost.ServiceProvider = webHost.Services; + var jellyfinDb = await appHost.ServiceProvider.GetRequiredService<IDbContextFactory<JellyfinDb>>().CreateDbContextAsync().ConfigureAwait(false); + await using (jellyfinDb.ConfigureAwait(false)) + { + if ((await jellyfinDb.Database.GetPendingMigrationsAsync().ConfigureAwait(false)).Any()) + { + _logger.LogInformation("There are pending EFCore migrations in the database. Applying... (This may take a while, do not stop Jellyfin)"); + await jellyfinDb.Database.MigrateAsync().ConfigureAwait(false); + _logger.LogInformation("EFCore migrations applied successfully"); + } + } + await appHost.InitializeServices().ConfigureAwait(false); Migrations.MigrationRunner.Run(appHost, _loggerFactory); @@ -236,10 +247,13 @@ namespace Jellyfin.Server { _logger.LogInformation("Running query planner optimizations in the database... This might take a while"); // Run before disposing the application - using var context = appHost.Resolve<JellyfinDbProvider>().CreateContext(); - if (context.Database.IsSqlite()) + var context = await appHost.ServiceProvider.GetRequiredService<IDbContextFactory<JellyfinDb>>().CreateDbContextAsync().ConfigureAwait(false); + await using (context.ConfigureAwait(false)) { - context.Database.ExecuteSqlRaw("PRAGMA optimize"); + if (context.Database.IsSqlite()) + { + await context.Database.ExecuteSqlRawAsync("PRAGMA optimize").ConfigureAwait(false); + } } } |
