aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Data
diff options
context:
space:
mode:
authorShadowghost <Shadowghost@users.noreply.github.com>2026-09-27 16:30:59 -0400
committerCody Robibero <cody@robibe.ro>2026-09-27 16:30:59 -0400
commitc5f5377e00b64058b5c04ca82cefd6cb646a3638 (patch)
treecf1b202ba189b62ed52d46d35a00f9687f5c02f9 /Emby.Server.Implementations/Data
parent3142fcd12fc063ea4b4a181c2af7384e6f2c1683 (diff)
Backport pull request #18196 from jellyfin/release-12.z
Skip statistics on an empty library and refresh them after every scan Original-merge: 83b89218e54754b22831399d592cd0f4b6185812 Merged-by: crobibero <cody@robibe.ro> Backported-by: Cody Robibero <cody@robibe.ro>
Diffstat (limited to 'Emby.Server.Implementations/Data')
-rw-r--r--Emby.Server.Implementations/Data/RefreshDatabaseStatisticsPostScanTask.cs35
1 files changed, 35 insertions, 0 deletions
diff --git a/Emby.Server.Implementations/Data/RefreshDatabaseStatisticsPostScanTask.cs b/Emby.Server.Implementations/Data/RefreshDatabaseStatisticsPostScanTask.cs
new file mode 100644
index 0000000000..be1fe660c9
--- /dev/null
+++ b/Emby.Server.Implementations/Data/RefreshDatabaseStatisticsPostScanTask.cs
@@ -0,0 +1,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);
+ }
+}