using System;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Database.Implementations;
using MediaBrowser.Controller.Library;
namespace Emby.Server.Implementations.Data;
///
/// Refreshes the database statistics after every library scan.
///
///
/// 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.
///
public class RefreshDatabaseStatisticsPostScanTask : ILibraryPostScanTask
{
private readonly IJellyfinDatabaseProvider _databaseProvider;
///
/// Initializes a new instance of the class.
///
/// The database provider.
public RefreshDatabaseStatisticsPostScanTask(IJellyfinDatabaseProvider databaseProvider)
{
_databaseProvider = databaseProvider;
}
///
public async Task Run(IProgress progress, CancellationToken cancellationToken)
{
await _databaseProvider.RefreshStatistics(cancellationToken).ConfigureAwait(false);
progress.Report(100);
}
}