From 6bb7980827f215aa4fd1bd082dde5716077f6449 Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Wed, 2 Aug 2023 11:31:25 -0500 Subject: [PATCH] fix: Preview and stat logging are more accurate The assignment logic in the DTO objects changes the end result of what gets synced. The preview and stat logic now first assigns config values to the old DTO object to get a more accurate preview of what the new values will be. --- .../QualityProfilePreviewPhase.cs | 36 ++++++++----------- .../QualityProfileStatCalculator.cs | 21 +++++------ 2 files changed, 22 insertions(+), 35 deletions(-) diff --git a/src/Recyclarr.Cli/Pipelines/QualityProfile/PipelinePhases/QualityProfilePreviewPhase.cs b/src/Recyclarr.Cli/Pipelines/QualityProfile/PipelinePhases/QualityProfilePreviewPhase.cs index 26a39d3d..60cf8512 100644 --- a/src/Recyclarr.Cli/Pipelines/QualityProfile/PipelinePhases/QualityProfilePreviewPhase.cs +++ b/src/Recyclarr.Cli/Pipelines/QualityProfile/PipelinePhases/QualityProfilePreviewPhase.cs @@ -50,37 +50,29 @@ public class QualityProfilePreviewPhase .AddColumn("[bold]Current[/]") .AddColumn("[bold]New[/]"); - static string YesNo(bool? val) => val is true ? "Yes" : "No"; - static string Null(T? val) => val is null ? "" : val.ToString() ?? ""; - - var dto = profile.ProfileDto; - var config = profile.ProfileConfig.Profile; + var oldDto = profile.ProfileDto; + var newDto = profile.BuildUpdatedDto(); - table.AddRow("Name", dto.Name, config.Name); - table.AddRow("Upgrades Allowed?", YesNo(dto.UpgradeAllowed), YesNo(config.UpgradeAllowed)); + table.AddRow("Name", oldDto.Name, newDto.Name); + table.AddRow("Upgrades Allowed?", YesNo(oldDto.UpgradeAllowed), YesNo(newDto.UpgradeAllowed)); + table.AddRow("Minimum Format Score", Null(oldDto.MinFormatScore), Null(newDto.MinFormatScore)); - if (config.UpgradeUntilQuality is not null) + // ReSharper disable once InvertIf + if (newDto.UpgradeAllowed is true) { table.AddRow("Upgrade Until Quality", - Null(dto.Items.FindGroupById(dto.Cutoff)?.Name), - Null(config.UpgradeUntilQuality)); - } + Null(oldDto.Items.FindCutoff(oldDto.Cutoff)), + Null(newDto.Items.FindCutoff(newDto.Cutoff))); - if (config.MinFormatScore is not null) - { - table.AddRow("Minimum Format Score", - Null(dto.MinFormatScore), - Null(config.MinFormatScore)); - } - - if (config.UpgradeUntilScore is not null) - { table.AddRow("Upgrade Until Score", - Null(dto.CutoffFormatScore), - Null(config.UpgradeUntilScore)); + Null(oldDto.CutoffFormatScore), + Null(newDto.CutoffFormatScore)); } return table; + + static string YesNo(bool? val) => val is true ? "Yes" : "No"; + static string Null(T? val) => val is null ? "" : val.ToString() ?? ""; } private static IRenderable SetupQualityItemTable(UpdatedQualityProfile profile) diff --git a/src/Recyclarr.Cli/Pipelines/QualityProfile/PipelinePhases/QualityProfileStatCalculator.cs b/src/Recyclarr.Cli/Pipelines/QualityProfile/PipelinePhases/QualityProfileStatCalculator.cs index 120ad30d..d5ed9391 100644 --- a/src/Recyclarr.Cli/Pipelines/QualityProfile/PipelinePhases/QualityProfileStatCalculator.cs +++ b/src/Recyclarr.Cli/Pipelines/QualityProfile/PipelinePhases/QualityProfileStatCalculator.cs @@ -37,25 +37,20 @@ public class QualityProfileStatCalculator private void ProfileUpdates(ProfileWithStats stats, UpdatedQualityProfile profile) { - var dto = profile.ProfileDto; - var config = profile.ProfileConfig.Profile; + var oldDto = profile.ProfileDto; + var newDto = profile.BuildUpdatedDto(); + + Log("Upgrade Allowed", oldDto.UpgradeAllowed, newDto.UpgradeAllowed); + Log("Cutoff", oldDto.Items.FindCutoff(oldDto.Cutoff), newDto.Items.FindCutoff(newDto.Cutoff)); + Log("Cutoff Score", oldDto.CutoffFormatScore, newDto.CutoffFormatScore); + Log("Minimum Score", oldDto.MinFormatScore, newDto.MinFormatScore); + return; void Log(string msg, T oldValue, T newValue) { _log.Debug("{Msg}: {Old} -> {New}", msg, oldValue, newValue); stats.ProfileChanged |= !EqualityComparer.Default.Equals(oldValue, newValue); } - - var upgradeAllowed = config.UpgradeAllowed is not null; - Log("Upgrade Allowed", dto.UpgradeAllowed, upgradeAllowed); - - if (upgradeAllowed) - { - Log("Cutoff", dto.Items.FindCutoff(dto.Cutoff), config.UpgradeUntilQuality); - Log("Cutoff Score", dto.CutoffFormatScore, config.UpgradeUntilScore); - } - - Log("Minimum Score", dto.MinFormatScore, config.MinFormatScore); } private static void QualityUpdates(ProfileWithStats stats, UpdatedQualityProfile profile)