fix: CF sync stats print to console again

Share code between the LogPhase and PreviewPhase classes.
pull/231/head
Robert Dailey 2 months ago
parent d4b582076a
commit 921a4cd9eb

@ -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
}
}

@ -11,4 +11,7 @@ public record CustomFormatTransactionData
public Collection<CustomFormatData> UpdatedCustomFormats { get; } = new();
public Collection<ConflictingCustomFormat> ConflictingCustomFormats { get; } = new();
public Collection<CustomFormatData> UnchangedCustomFormats { get; } = new();
public int TotalCustomFormatChanges =>
NewCustomFormats.Count + UpdatedCustomFormats.Count + DeletedCustomFormats.Count;
}

@ -28,6 +28,6 @@ public class CustomFormatLogPhase(ILogger log) : ILogPipelinePhase<CustomFormatP
public void LogPersistenceResults(CustomFormatPipelineContext context)
{
// Logging is done (and shared with) in CustomFormatPreviewPhase
context.LogTransactions(log);
}
}

@ -6,68 +6,6 @@ public class CustomFormatPreviewPhase(ILogger log) : IPreviewPipelinePhase<Custo
{
public void Execute(CustomFormatPipelineContext context)
{
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 = 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);
}
}

Loading…
Cancel
Save