diff options
| author | Shane Powell <killerbee@club88.co.nz> | 2025-09-04 15:11:58 +1200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-03 21:11:58 -0600 |
| commit | 71048917dd421e4a18684d6b7878083a596ed821 (patch) | |
| tree | 397830044da2423f2e99092e0a95ed44a8f6b5d0 /Emby.Server.Implementations | |
| parent | 11eab1b6631fb325d43aa648b25e4b6da7c373f9 (diff) | |
AudioNormalizationTask db progress saving (#14550)
Diffstat (limited to 'Emby.Server.Implementations')
| -rw-r--r-- | Emby.Server.Implementations/ScheduledTasks/Tasks/AudioNormalizationTask.cs | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/Emby.Server.Implementations/ScheduledTasks/Tasks/AudioNormalizationTask.cs b/Emby.Server.Implementations/ScheduledTasks/Tasks/AudioNormalizationTask.cs index 24992c44a..4245c9b12 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 : IScheduledTask private 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 : IScheduledTask foreach (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 : IScheduledTask string.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 file cancellationToken).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 gain albumComplete++; double albumPercent = albumComplete; @@ -133,7 +149,13 @@ public partial class AudioNormalizationTask : IScheduledTask // Update progress to start at the track gain percent calculation percent += nextPercent; - _itemRepository.SaveItems(albums, cancellationToken); + if (toSaveDbItems.Count > 1) + { + _itemRepository.SaveItems(toSaveDbItems, cancellationToken); + toSaveDbItems.Clear(); + } + + startDbSaveInterval = Stopwatch.GetTimestamp(); // Track gain var tracks = _libraryManager.GetItemList(new InternalItemsQuery { MediaTypes = [MediaType.Audio], IncludeItemTypes = [BaseItemKind.Audio], Parent = library, Recursive = true }); @@ -147,6 +169,18 @@ public partial class AudioNormalizationTask : IScheduledTask string.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 : IScheduledTask progress.Report(100 * (percent + (trackPercent * nextPercent))); } - _itemRepository.SaveItems(tracks, cancellationToken); + if (toSaveDbItems.Count > 1) + { + _itemRepository.SaveItems(toSaveDbItems, cancellationToken); + } // Update progress numComplete++; |
