From 5c9f70c3752bd7297cb85bdc7ce748363a16ad8b Mon Sep 17 00:00:00 2001 From: Shadowghost Date: Wed, 30 Apr 2025 09:29:13 +0200 Subject: Cleanup Tasks and Validators --- .../ScheduledTasks/Tasks/OptimizeDatabaseTask.cs | 114 ++++++++++----------- 1 file changed, 54 insertions(+), 60 deletions(-) (limited to 'Emby.Server.Implementations/ScheduledTasks/Tasks/OptimizeDatabaseTask.cs') diff --git a/Emby.Server.Implementations/ScheduledTasks/Tasks/OptimizeDatabaseTask.cs b/Emby.Server.Implementations/ScheduledTasks/Tasks/OptimizeDatabaseTask.cs index 4d3a04377..bf8ffaf47 100644 --- a/Emby.Server.Implementations/ScheduledTasks/Tasks/OptimizeDatabaseTask.cs +++ b/Emby.Server.Implementations/ScheduledTasks/Tasks/OptimizeDatabaseTask.cs @@ -5,84 +5,78 @@ using System.Threading.Tasks; using Jellyfin.Database.Implementations; using MediaBrowser.Model.Globalization; using MediaBrowser.Model.Tasks; -using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; -namespace Emby.Server.Implementations.ScheduledTasks.Tasks +namespace Emby.Server.Implementations.ScheduledTasks.Tasks; + +/// +/// Optimizes Jellyfin's database by issuing a VACUUM command. +/// +public class OptimizeDatabaseTask : IScheduledTask, IConfigurableScheduledTask { + private readonly ILogger _logger; + private readonly ILocalizationManager _localization; + private readonly IJellyfinDatabaseProvider _jellyfinDatabaseProvider; + /// - /// Optimizes Jellyfin's database by issuing a VACUUM command. + /// Initializes a new instance of the class. /// - public class OptimizeDatabaseTask : IScheduledTask, IConfigurableScheduledTask + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the JellyfinDatabaseProvider that can be used for provider specific operations. + public OptimizeDatabaseTask( + ILogger logger, + ILocalizationManager localization, + IJellyfinDatabaseProvider jellyfinDatabaseProvider) { - private readonly ILogger _logger; - private readonly ILocalizationManager _localization; - private readonly IDbContextFactory _provider; - private readonly IJellyfinDatabaseProvider _jellyfinDatabaseProvider; + _logger = logger; + _localization = localization; + _jellyfinDatabaseProvider = jellyfinDatabaseProvider; + } - /// - /// Initializes a new instance of the class. - /// - /// Instance of the interface. - /// Instance of the interface. - /// Instance of the interface. - /// Instance of the JellyfinDatabaseProvider that can be used for provider specific operations. - public OptimizeDatabaseTask( - ILogger logger, - ILocalizationManager localization, - IDbContextFactory provider, - IJellyfinDatabaseProvider jellyfinDatabaseProvider) - { - _logger = logger; - _localization = localization; - _provider = provider; - _jellyfinDatabaseProvider = jellyfinDatabaseProvider; - } + /// + public string Name => _localization.GetLocalizedString("TaskOptimizeDatabase"); + + /// + public string Description => _localization.GetLocalizedString("TaskOptimizeDatabaseDescription"); - /// - public string Name => _localization.GetLocalizedString("TaskOptimizeDatabase"); + /// + public string Category => _localization.GetLocalizedString("TasksMaintenanceCategory"); - /// - public string Description => _localization.GetLocalizedString("TaskOptimizeDatabaseDescription"); + /// + public string Key => "OptimizeDatabaseTask"; - /// - public string Category => _localization.GetLocalizedString("TasksMaintenanceCategory"); + /// + public bool IsHidden => false; - /// - public string Key => "OptimizeDatabaseTask"; + /// + public bool IsEnabled => true; - /// - public bool IsHidden => false; + /// + public bool IsLogged => true; - /// - public bool IsEnabled => true; + /// + public IEnumerable GetDefaultTriggers() + { + yield return new TaskTriggerInfo + { + Type = TaskTriggerInfoType.IntervalTrigger, + IntervalTicks = TimeSpan.FromHours(24).Ticks + }; + } - /// - public bool IsLogged => true; + /// + public async Task ExecuteAsync(IProgress progress, CancellationToken cancellationToken) + { + _logger.LogInformation("Optimizing and vacuuming jellyfin.db..."); - /// - public IEnumerable GetDefaultTriggers() + try { - return - [ - // Every so often - new TaskTriggerInfo { Type = TaskTriggerInfoType.IntervalTrigger, IntervalTicks = TimeSpan.FromHours(24).Ticks } - ]; + await _jellyfinDatabaseProvider.RunScheduledOptimisation(cancellationToken).ConfigureAwait(false); } - - /// - public async Task ExecuteAsync(IProgress progress, CancellationToken cancellationToken) + catch (Exception e) { - _logger.LogInformation("Optimizing and vacuuming jellyfin.db..."); - - try - { - await _jellyfinDatabaseProvider.RunScheduledOptimisation(cancellationToken).ConfigureAwait(false); - } - catch (Exception e) - { - _logger.LogError(e, "Error while optimizing jellyfin.db"); - } + _logger.LogError(e, "Error while optimizing jellyfin.db"); } } } -- cgit v1.2.3