From ec9356b36e48f10f0a9583a34c4d20b59fb76545 Mon Sep 17 00:00:00 2001 From: MBucari Date: Mon, 27 Mar 2023 18:57:41 -0600 Subject: [PATCH] Do not import orphaned episodes (#553) --- Source/ApplicationServices/LibraryCommands.cs | 3 ++- Source/AudibleUtilities/ApiExtended.cs | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Source/ApplicationServices/LibraryCommands.cs b/Source/ApplicationServices/LibraryCommands.cs index f804f994..2a8e8cd7 100644 --- a/Source/ApplicationServices/LibraryCommands.cs +++ b/Source/ApplicationServices/LibraryCommands.cs @@ -282,7 +282,8 @@ namespace ApplicationServices catch(ImportValidationException ex) { await logDtoItemsAsync(ex.Items, ex.InnerExceptions.ToArray()); - throw; + //If ImportValidationException is thrown, all Dto items get logged as part of the exception + throw new AggregateException(ex.InnerExceptions); } async Task logDtoItemsAsync(IEnumerable dtoItems, IEnumerable exceptions = null) diff --git a/Source/AudibleUtilities/ApiExtended.cs b/Source/AudibleUtilities/ApiExtended.cs index 97caa4aa..c9c202ae 100644 --- a/Source/AudibleUtilities/ApiExtended.cs +++ b/Source/AudibleUtilities/ApiExtended.cs @@ -152,13 +152,17 @@ namespace AudibleUtilities SetSeries(parent, children); } + int orphansRemoved = items.RemoveAll(i => (i.IsEpisodes || i.IsSeriesParent) && i.Series is null); + if (orphansRemoved > 0) + Serilog.Log.Debug("{orphansRemoved} podcast orphans not imported", orphansRemoved); + sw.Stop(); totalTime += sw.Elapsed; Serilog.Log.Logger.Information("Completed indexing series episodes after {elappsed_ms} ms.", sw.ElapsedMilliseconds); Serilog.Log.Logger.Information($"Completed library scan in {totalTime.TotalMilliseconds:F0} ms."); - var allExceptions = IValidator.GetAllValidators().SelectMany(v => v.Validate(items)); - if (allExceptions?.Any() is true) + var allExceptions = IValidator.GetAllValidators().SelectMany(v => v.Validate(items)).ToList(); + if (allExceptions?.Count > 0) throw new ImportValidationException(items, allExceptions); return items;