From 69baa9c4679d376f001cc71ec0a0d9a1791e7adf Mon Sep 17 00:00:00 2001 From: Fernando Fernández Date: Tue, 11 May 2021 23:26:00 +0200 Subject: Run SQLite query planner optimization at shutdown/restart --- Jellyfin.Server/Program.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'Jellyfin.Server/Program.cs') diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index c10b2ddb3..d0f10b467 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -12,10 +12,12 @@ using System.Threading.Tasks; using CommandLine; using Emby.Server.Implementations; using Emby.Server.Implementations.IO; +using Jellyfin.Server.Implementations; using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Net; using MediaBrowser.Controller.Extensions; using Microsoft.AspNetCore.Hosting; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; @@ -221,6 +223,14 @@ namespace Jellyfin.Server finally { appHost.Dispose(); + _logger.LogInformation("Running query planner optimizations in the database... This might take a while"); + + // Run after disposing the application + using var context = new JellyfinDbProvider(appHost.ServiceProvider, appPaths).CreateContext(); + if (context.Database.IsSqlite()) + { + context.Database.ExecuteSqlRaw("PRAGMA optimize"); + } } if (_restartOnShutdown) -- cgit v1.2.3 From 6db229af5deb6a00035ddcfebc4fd9db3b6a5336 Mon Sep 17 00:00:00 2001 From: Fernando Fernández Date: Mon, 24 May 2021 10:48:01 +0200 Subject: Address review comments --- Jellyfin.Server/Program.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Jellyfin.Server/Program.cs') diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index d0f10b467..3a3d7415b 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -222,15 +222,15 @@ namespace Jellyfin.Server } finally { - appHost.Dispose(); _logger.LogInformation("Running query planner optimizations in the database... This might take a while"); - - // Run after disposing the application + // Run before disposing the application using var context = new JellyfinDbProvider(appHost.ServiceProvider, appPaths).CreateContext(); if (context.Database.IsSqlite()) { context.Database.ExecuteSqlRaw("PRAGMA optimize"); } + + appHost.Dispose(); } if (_restartOnShutdown) -- cgit v1.2.3