From 921a4cd9eb88e3e6a33c66fbe3a2f1585673399b Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Thu, 29 Feb 2024 17:06:27 -0600 Subject: [PATCH] fix: CF sync stats print to console again Share code between the LogPhase and PreviewPhase classes. --- .../CustomFormatPipelineExtensions.cs | 73 +++++++++++++++++++ .../Models/CustomFormatTransactionData.cs | 3 + .../PipelinePhases/CustomFormatLogPhase.cs | 2 +- .../CustomFormatPreviewPhase.cs | 64 +--------------- 4 files changed, 78 insertions(+), 64 deletions(-) create mode 100644 src/Recyclarr.Cli/Pipelines/CustomFormat/CustomFormatPipelineExtensions.cs diff --git a/src/Recyclarr.Cli/Pipelines/CustomFormat/CustomFormatPipelineExtensions.cs b/src/Recyclarr.Cli/Pipelines/CustomFormat/CustomFormatPipelineExtensions.cs new file mode 100644 index 00000000..5110cfd3 --- /dev/null +++ b/src/Recyclarr.Cli/Pipelines/CustomFormat/CustomFormatPipelineExtensions.cs @@ -0,0 +1,73 @@ +namespace Recyclarr.Cli.Pipelines.CustomFormat; + +internal static class CustomFormatPipelineExtensions +{ + public static void LogTransactions(this CustomFormatPipelineContext context, ILogger log) + { + var transactions = context.TransactionOutput; + + foreach (var (guideCf, conflictingId) in transactions.ConflictingCustomFormats) + { + log.Warning( + "Custom Format with name {Name} (Trash ID: {TrashId}) will be skipped because another " + + "CF already exists with that name (ID: {ConflictId}). To fix the conflict, delete or " + + "rename the CF with the mentioned name", + guideCf.Name, guideCf.TrashId, conflictingId); + } + + var created = transactions.NewCustomFormats; + if (created.Count > 0) + { + log.Information("Created {Count} New Custom Formats", created.Count); + + foreach (var cf in created) + { + log.Debug("> Created: {TrashId} ({Name})", cf.TrashId, cf.Name); + } + } + + var updated = transactions.UpdatedCustomFormats; + if (updated.Count > 0) + { + log.Information("Updated {Count} Existing Custom Formats", updated.Count); + + foreach (var cf in updated) + { + log.Debug("> Updated: {TrashId} ({Name})", cf.TrashId, cf.Name); + } + } + + var skipped = transactions.UnchangedCustomFormats; + if (skipped.Count > 0) + { + log.Information("Skipped {Count} Custom Formats that did not change", skipped.Count); + log.Debug("Custom Formats Skipped: {CustomFormats}", + skipped.ToDictionary(k => k.TrashId, v => v.Name)); + + // Do not print skipped CFs to console; they are too verbose + } + + var deleted = transactions.DeletedCustomFormats; + if (deleted.Count > 0) + { + log.Information("Deleted {Count} Custom Formats", deleted.Count); + + foreach (var mapping in deleted) + { + log.Debug("> Deleted: {TrashId} ({CustomFormatName})", mapping.TrashId, mapping.CustomFormatName); + } + } + + var totalCount = transactions.TotalCustomFormatChanges; + if (totalCount > 0) + { + log.Information("Total of {Count} custom formats were synced", totalCount); + } + else + { + log.Information("All custom formats are already up to date!"); + } + + // Logging is done (and shared with) in CustomFormatPreviewPhase + } +} diff --git a/src/Recyclarr.Cli/Pipelines/CustomFormat/Models/CustomFormatTransactionData.cs b/src/Recyclarr.Cli/Pipelines/CustomFormat/Models/CustomFormatTransactionData.cs index f4240b32..ffb43b1e 100644 --- a/src/Recyclarr.Cli/Pipelines/CustomFormat/Models/CustomFormatTransactionData.cs +++ b/src/Recyclarr.Cli/Pipelines/CustomFormat/Models/CustomFormatTransactionData.cs @@ -11,4 +11,7 @@ public record CustomFormatTransactionData public Collection UpdatedCustomFormats { get; } = new(); public Collection ConflictingCustomFormats { get; } = new(); public Collection UnchangedCustomFormats { get; } = new(); + + public int TotalCustomFormatChanges => + NewCustomFormats.Count + UpdatedCustomFormats.Count + DeletedCustomFormats.Count; } diff --git a/src/Recyclarr.Cli/Pipelines/CustomFormat/PipelinePhases/CustomFormatLogPhase.cs b/src/Recyclarr.Cli/Pipelines/CustomFormat/PipelinePhases/CustomFormatLogPhase.cs index 48358d3b..ff91e6ee 100644 --- a/src/Recyclarr.Cli/Pipelines/CustomFormat/PipelinePhases/CustomFormatLogPhase.cs +++ b/src/Recyclarr.Cli/Pipelines/CustomFormat/PipelinePhases/CustomFormatLogPhase.cs @@ -28,6 +28,6 @@ public class CustomFormatLogPhase(ILogger log) : ILogPipelinePhase 0) - { - log.Information("Created {Count} New Custom Formats", created.Count); - - foreach (var cf in created) - { - log.Debug("> Created: {TrashId} ({Name})", cf.TrashId, cf.Name); - } - } - - var updated = transactions.UpdatedCustomFormats; - if (updated.Count > 0) - { - log.Information("Updated {Count} Existing Custom Formats", updated.Count); - - foreach (var cf in updated) - { - log.Debug("> Updated: {TrashId} ({Name})", cf.TrashId, cf.Name); - } - } - - var skipped = transactions.UnchangedCustomFormats; - if (skipped.Count > 0) - { - log.Information("Skipped {Count} Custom Formats that did not change", skipped.Count); - log.Debug("Custom Formats Skipped: {CustomFormats}", - skipped.ToDictionary(k => k.TrashId, v => v.Name)); - - // Do not print skipped CFs to console; they are too verbose - } - - var deleted = transactions.DeletedCustomFormats; - if (deleted.Count > 0) - { - log.Information("Deleted {Count} Custom Formats", deleted.Count); - - foreach (var mapping in deleted) - { - log.Debug("> Deleted: {TrashId} ({CustomFormatName})", mapping.TrashId, mapping.CustomFormatName); - } - } - - var totalCount = created.Count + updated.Count + deleted.Count; - if (totalCount > 0) - { - log.Information("Total of {Count} custom formats were synced", totalCount); - } - else - { - log.Information("All custom formats are already up to date!"); - } + context.LogTransactions(log); } }