< Summary - Jellyfin

Information
Class: Emby.Server.Implementations.ScheduledTasks.Tasks.OptimizeDatabaseTask
Assembly: Emby.Server.Implementations
File(s): /srv/git/jellyfin/Emby.Server.Implementations/ScheduledTasks/Tasks/OptimizeDatabaseTask.cs
Line coverage
45%
Covered lines: 5
Uncovered lines: 6
Coverable lines: 11
Total lines: 82
Line coverage: 45.4%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Name()100%11100%
get_Description()100%210%
get_Category()100%210%
get_Key()100%210%
get_IsHidden()100%210%
get_IsEnabled()100%210%
get_IsLogged()100%210%

File(s)

/srv/git/jellyfin/Emby.Server.Implementations/ScheduledTasks/Tasks/OptimizeDatabaseTask.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Threading;
 4using System.Threading.Tasks;
 5using Jellyfin.Database.Implementations;
 6using MediaBrowser.Model.Globalization;
 7using MediaBrowser.Model.Tasks;
 8using Microsoft.Extensions.Logging;
 9
 10namespace Emby.Server.Implementations.ScheduledTasks.Tasks;
 11
 12/// <summary>
 13/// Optimizes Jellyfin's database by issuing a VACUUM command.
 14/// </summary>
 15public class OptimizeDatabaseTask : IScheduledTask, IConfigurableScheduledTask
 16{
 17    private readonly ILogger<OptimizeDatabaseTask> _logger;
 18    private readonly ILocalizationManager _localization;
 19    private readonly IJellyfinDatabaseProvider _jellyfinDatabaseProvider;
 20
 21    /// <summary>
 22    /// Initializes a new instance of the <see cref="OptimizeDatabaseTask" /> class.
 23    /// </summary>
 24    /// <param name="logger">Instance of the <see cref="ILogger"/> interface.</param>
 25    /// <param name="localization">Instance of the <see cref="ILocalizationManager"/> interface.</param>
 26    /// <param name="jellyfinDatabaseProvider">Instance of the JellyfinDatabaseProvider that can be used for provider sp
 27    public OptimizeDatabaseTask(
 28        ILogger<OptimizeDatabaseTask> logger,
 29        ILocalizationManager localization,
 30        IJellyfinDatabaseProvider jellyfinDatabaseProvider)
 31    {
 2132        _logger = logger;
 2133        _localization = localization;
 2134        _jellyfinDatabaseProvider = jellyfinDatabaseProvider;
 2135    }
 36
 37    /// <inheritdoc />
 2138    public string Name => _localization.GetLocalizedString("TaskOptimizeDatabase");
 39
 40    /// <inheritdoc />
 041    public string Description => _localization.GetLocalizedString("TaskOptimizeDatabaseDescription");
 42
 43    /// <inheritdoc />
 044    public string Category => _localization.GetLocalizedString("TasksMaintenanceCategory");
 45
 46    /// <inheritdoc />
 047    public string Key => "OptimizeDatabaseTask";
 48
 49    /// <inheritdoc />
 050    public bool IsHidden => false;
 51
 52    /// <inheritdoc />
 053    public bool IsEnabled => true;
 54
 55    /// <inheritdoc />
 056    public bool IsLogged => true;
 57
 58    /// <inheritdoc />
 59    public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
 60    {
 61        yield return new TaskTriggerInfo
 62        {
 63            Type = TaskTriggerInfoType.IntervalTrigger,
 64            IntervalTicks = TimeSpan.FromHours(24).Ticks
 65        };
 66    }
 67
 68    /// <inheritdoc />
 69    public async Task ExecuteAsync(IProgress<double> progress, CancellationToken cancellationToken)
 70    {
 71        _logger.LogInformation("Optimizing and vacuuming jellyfin.db...");
 72
 73        try
 74        {
 75            await _jellyfinDatabaseProvider.RunScheduledOptimisation(cancellationToken).ConfigureAwait(false);
 76        }
 77        catch (Exception e)
 78        {
 79            _logger.LogError(e, "Error while optimizing jellyfin.db");
 80        }
 81    }
 82}