aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/ScheduledTasks/Tasks/OptimizeDatabaseTask.cs
diff options
context:
space:
mode:
authorShadowghost <Ghost_of_Stone@web.de>2022-12-03 12:44:45 +0100
committerShadowghost <Ghost_of_Stone@web.de>2022-12-03 12:44:45 +0100
commitbcd992fb0604839c18a628850df095777d6cf6f9 (patch)
treeabd5da0cd5ff6a7043f00969b912a00067f344f7 /Emby.Server.Implementations/ScheduledTasks/Tasks/OptimizeDatabaseTask.cs
parent36994c17bf5f71f37a5002a51840306fa09fb0ef (diff)
parentdb2c0d4c91a952407ab7709d9ff5c86017e5753e (diff)
Merge remote-tracking branch 'upstream/master' into network-rewrite
Diffstat (limited to 'Emby.Server.Implementations/ScheduledTasks/Tasks/OptimizeDatabaseTask.cs')
-rw-r--r--Emby.Server.Implementations/ScheduledTasks/Tasks/OptimizeDatabaseTask.cs29
1 files changed, 15 insertions, 14 deletions
diff --git a/Emby.Server.Implementations/ScheduledTasks/Tasks/OptimizeDatabaseTask.cs b/Emby.Server.Implementations/ScheduledTasks/Tasks/OptimizeDatabaseTask.cs
index 98e45fa46..1efacd856 100644
--- a/Emby.Server.Implementations/ScheduledTasks/Tasks/OptimizeDatabaseTask.cs
+++ b/Emby.Server.Implementations/ScheduledTasks/Tasks/OptimizeDatabaseTask.cs
@@ -17,7 +17,7 @@ namespace Emby.Server.Implementations.ScheduledTasks.Tasks
{
private readonly ILogger<OptimizeDatabaseTask> _logger;
private readonly ILocalizationManager _localization;
- private readonly JellyfinDbProvider _provider;
+ private readonly IDbContextFactory<JellyfinDb> _provider;
/// <summary>
/// Initializes a new instance of the <see cref="OptimizeDatabaseTask" /> class.
@@ -28,7 +28,7 @@ namespace Emby.Server.Implementations.ScheduledTasks.Tasks
public OptimizeDatabaseTask(
ILogger<OptimizeDatabaseTask> logger,
ILocalizationManager localization,
- JellyfinDbProvider provider)
+ IDbContextFactory<JellyfinDb> provider)
{
_logger = logger;
_localization = localization;
@@ -70,30 +70,31 @@ namespace Emby.Server.Implementations.ScheduledTasks.Tasks
}
/// <inheritdoc />
- public Task ExecuteAsync(IProgress<double> progress, CancellationToken cancellationToken)
+ public async Task ExecuteAsync(IProgress<double> progress, CancellationToken cancellationToken)
{
_logger.LogInformation("Optimizing and vacuuming jellyfin.db...");
try
{
- using var context = _provider.CreateContext();
- if (context.Database.IsSqlite())
+ var context = await _provider.CreateDbContextAsync(cancellationToken).ConfigureAwait(false);
+ await using (context.ConfigureAwait(false))
{
- context.Database.ExecuteSqlRaw("PRAGMA optimize");
- context.Database.ExecuteSqlRaw("VACUUM");
- _logger.LogInformation("jellyfin.db optimized successfully!");
- }
- else
- {
- _logger.LogInformation("This database doesn't support optimization");
+ if (context.Database.IsSqlite())
+ {
+ await context.Database.ExecuteSqlRawAsync("PRAGMA optimize", cancellationToken).ConfigureAwait(false);
+ await context.Database.ExecuteSqlRawAsync("VACUUM", cancellationToken).ConfigureAwait(false);
+ _logger.LogInformation("jellyfin.db optimized successfully!");
+ }
+ else
+ {
+ _logger.LogInformation("This database doesn't support optimization");
+ }
}
}
catch (Exception e)
{
_logger.LogError(e, "Error while optimizing jellyfin.db");
}
-
- return Task.CompletedTask;
}
}
}