fix: Show a warning for duplicate scores

pull/138/head
Robert Dailey 2 years ago
parent a63d570ec5
commit 1619bd8817

@ -23,6 +23,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Use compact JSON for HTTP request/response body in debug log files. This makes logs much easier to
scroll through.
- Sonarr: Run version enforcement logic when using CFs instead of RPs.
- A warning is now displayed when the same custom format is assigned multiple times to the same
quality profile.
## [2.5.0] - 2022-09-11

@ -204,6 +204,25 @@ internal class CustomFormatUpdater : ICustomFormatUpdater
_console.Output.WriteLine("");
}
if (_guideProcessor.DuplicateScores.Any())
{
foreach (var (profileName, duplicates) in _guideProcessor.DuplicateScores)
foreach (var (trashId, dupeScores) in duplicates)
{
_log.Warning(
"Custom format with trash ID {TrashId} is duplicated {Count} times in quality profile " +
"{ProfileName} with the following scores: {Scores}",
trashId, dupeScores.Count, profileName, dupeScores);
}
_log.Warning(
"When the same CF is specified multiple times with different scores in the same quality profile, " +
"only the score from the first occurrence is used. To resolve the duplication warnings above, " +
"remove the duplicate trash IDs from your YAML config");
_console.Output.WriteLine("");
}
if (_guideProcessor.CustomFormatsWithOutdatedNames.Count > 0)
{
_log.Warning("One or more custom format names in your YAML config have been renamed in the guide and " +

@ -40,6 +40,9 @@ internal class GuideProcessor : IGuideProcessor
public IReadOnlyCollection<(string name, string trashId, string profileName)> CustomFormatsWithoutScore
=> _steps.QualityProfile.CustomFormatsWithoutScore;
public IReadOnlyDictionary<string, Dictionary<string, HashSet<int>>> DuplicateScores
=> _steps.QualityProfile.DuplicateScores;
public IReadOnlyCollection<TrashIdMapping> DeletedCustomFormatsInCache
=> _steps.CustomFormat.DeletedCustomFormatsInCache;

@ -6,5 +6,6 @@ public interface IQualityProfileStep
{
IDictionary<string, QualityProfileCustomFormatScoreMapping> ProfileScores { get; }
IReadOnlyCollection<(string name, string trashId, string profileName)> CustomFormatsWithoutScore { get; }
IReadOnlyDictionary<string, Dictionary<string, HashSet<int>>> DuplicateScores { get; }
void Process(IEnumerable<ProcessedConfigData> configData);
}

@ -1,3 +1,4 @@
using Common.Extensions;
using TrashLib.Services.CustomFormat.Models;
namespace TrashLib.Services.CustomFormat.Processors.GuideSteps;
@ -6,12 +7,15 @@ internal class QualityProfileStep : IQualityProfileStep
{
private readonly Dictionary<string, QualityProfileCustomFormatScoreMapping> _profileScores = new();
private readonly List<(string name, string trashId, string profileName)> _customFormatsWithoutScore = new();
private readonly Dictionary<string, Dictionary<string, HashSet<int>>> _duplicateScores = new();
public IDictionary<string, QualityProfileCustomFormatScoreMapping> ProfileScores => _profileScores;
public IReadOnlyCollection<(string name, string trashId, string profileName)> CustomFormatsWithoutScore
=> _customFormatsWithoutScore;
public IReadOnlyDictionary<string, Dictionary<string, HashSet<int>>> DuplicateScores => _duplicateScores;
public void Process(IEnumerable<ProcessedConfigData> configData)
{
foreach (var config in configData)
@ -46,6 +50,15 @@ internal class QualityProfileStep : IQualityProfileStep
ProfileScores[profile.Name] = mapping;
}
// Check if this score was specified multiple times for the same profile. For each duplicate, we record
// the score of the second and onward occurrences for logging/reporting purposes.
var dupe = mapping.Mapping.FirstOrDefault(x => x.CustomFormat.TrashId.EqualsIgnoreCase(cf.TrashId));
if (dupe is not null)
{
_duplicateScores.GetOrCreate(profile.Name).GetOrCreate(cf.TrashId).Add(scoreToUse.Value);
continue;
}
mapping.Mapping.Add(new FormatMappingEntry(cf, scoreToUse.Value));
}
}

@ -15,6 +15,7 @@ internal interface IGuideProcessor
IReadOnlyCollection<TrashIdMapping> DeletedCustomFormatsInCache { get; }
IReadOnlyCollection<(string, string)> CustomFormatsWithOutdatedNames { get; }
IDictionary<string, List<ProcessedCustomFormatData>> DuplicatedCustomFormats { get; }
IReadOnlyDictionary<string, Dictionary<string, HashSet<int>>> DuplicateScores { get; }
Task BuildGuideDataAsync(IEnumerable<CustomFormatConfig> config, CustomFormatCache? cache,
IGuideService guideService);

Loading…
Cancel
Save