The Free Software Media System - Server Backend & API
AudioNormalizationTask db progress saving (#14550)
Shane Powell71048917dd42
diff --git a/Emby.Server.Implementations/ScheduledTasks/Tasks/AudioNormalizationTask.cs b/Emby.Server.Implementations/ScheduledTasks/Tasks/AudioNormalizationTask.csindex 24992c44a6..4245c9b12c 100644--- a/Emby.Server.Implementations/ScheduledTasks/Tasks/AudioNormalizationTask.cs+++ b/Emby.Server.Implementations/ScheduledTasks/Tasks/AudioNormalizationTask.cs@@ -33,6 +33,8 @@ public partial class AudioNormalizationTask : IScheduledTaskprivate readonly ILocalizationManager _localization;private readonly ILogger<AudioNormalizationTask> _logger;+ private static readonly TimeSpan _dbSaveInterval = TimeSpan.FromMinutes(5);+/// <summary>/// Initializes a new instance of the <see cref="AudioNormalizationTask"/> class./// </summary>@@ -82,7 +84,9 @@ public partial class AudioNormalizationTask : IScheduledTaskforeach (var library in libraries){+ var startDbSaveInterval = Stopwatch.GetTimestamp();var albums = _libraryManager.GetItemList(new InternalItemsQuery { IncludeItemTypes = [BaseItemKind.MusicAlbum], Parent = library, Recursive = true });+ var toSaveDbItems = new List<BaseItem>();double nextPercent = numComplete + 1;nextPercent /= libraries.Length;@@ -114,6 +118,7 @@ public partial class AudioNormalizationTask : IScheduledTaskstring.Format(CultureInfo.InvariantCulture, "-f concat -safe 0 -i \"{0}\"", tempFile),OperatingSystem.IsWindows(), // Wait for process to exit on Windows before we try deleting the concat filecancellationToken).ConfigureAwait(false);+ toSaveDbItems.Add(a);}finally{@@ -122,6 +127,17 @@ public partial class AudioNormalizationTask : IScheduledTask}}+ if (Stopwatch.GetElapsedTime(startDbSaveInterval) > _dbSaveInterval)+ {+ if (toSaveDbItems.Count > 1)+ {+ _itemRepository.SaveItems(toSaveDbItems, cancellationToken);+ toSaveDbItems.Clear();+ }++ startDbSaveInterval = Stopwatch.GetTimestamp();+ }+// Update sub-progress for album gainalbumComplete++;double albumPercent = albumComplete;@@ -133,7 +149,13 @@ public partial class AudioNormalizationTask : IScheduledTask// Update progress to start at the track gain percent calculationpercent += nextPercent;- _itemRepository.SaveItems(albums, cancellationToken);+ if (toSaveDbItems.Count > 1)+ {+ _itemRepository.SaveItems(toSaveDbItems, cancellationToken);+ toSaveDbItems.Clear();+ }++ startDbSaveInterval = Stopwatch.GetTimestamp();// Track gainvar tracks = _libraryManager.GetItemList(new InternalItemsQuery { MediaTypes = [MediaType.Audio], IncludeItemTypes = [BaseItemKind.Audio], Parent = library, Recursive = true });@@ -147,6 +169,18 @@ public partial class AudioNormalizationTask : IScheduledTaskstring.Format(CultureInfo.InvariantCulture, "-i \"{0}\"", t.Path.Replace("\"", "\\\"", StringComparison.Ordinal)),false,cancellationToken).ConfigureAwait(false);+ toSaveDbItems.Add(t);+ }++ if (Stopwatch.GetElapsedTime(startDbSaveInterval) > _dbSaveInterval)+ {+ if (toSaveDbItems.Count > 1)+ {+ _itemRepository.SaveItems(toSaveDbItems, cancellationToken);+ toSaveDbItems.Clear();+ }++ startDbSaveInterval = Stopwatch.GetTimestamp();}// Update sub-progress for track gain@@ -157,7 +191,10 @@ public partial class AudioNormalizationTask : IScheduledTaskprogress.Report(100 * (percent + (trackPercent * nextPercent)));}- _itemRepository.SaveItems(tracks, cancellationToken);+ if (toSaveDbItems.Count > 1)+ {+ _itemRepository.SaveItems(toSaveDbItems, cancellationToken);+ }// Update progressnumComplete++;