aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Data/RefreshDatabaseStatisticsPostScanTask.cs
blob: be1fe660c9418e38acd560c5f33c54193de15f78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Database.Implementations;
using MediaBrowser.Controller.Library;

namespace Emby.Server.Implementations.Data;

/// <summary>
/// Refreshes the database statistics after every library scan.
/// </summary>
/// <remarks>
/// The scheduled optimization skips itself while a scan runs, so without this the first scan of a new server
/// leaves every query planned for an empty library until the next scheduled run.
/// </remarks>
public class RefreshDatabaseStatisticsPostScanTask : ILibraryPostScanTask
{
    private readonly IJellyfinDatabaseProvider _databaseProvider;

    /// <summary>
    /// Initializes a new instance of the <see cref="RefreshDatabaseStatisticsPostScanTask"/> class.
    /// </summary>
    /// <param name="databaseProvider">The database provider.</param>
    public RefreshDatabaseStatisticsPostScanTask(IJellyfinDatabaseProvider databaseProvider)
    {
        _databaseProvider = databaseProvider;
    }

    /// <inheritdoc />
    public async Task Run(IProgress<double> progress, CancellationToken cancellationToken)
    {
        await _databaseProvider.RefreshStatistics(cancellationToken).ConfigureAwait(false);
        progress.Report(100);
    }
}