fix(radarr): do not invoke api for profile when there's no updates

recyclarr
Robert Dailey 3 years ago
parent 746d2f7f91
commit 00ed14f55c

@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- The log message listing custom formats without scores in the guide now prints information one per
line (improved readability)
- Duplicate custom formats in the guide now issue a warning and get skipped.
- Do not invoke the Radarr API to update a quality profile if there are no updated scores inside it.
## [1.4.0] - 2021-05-14

@ -18,6 +18,52 @@ namespace Trash.Tests.Radarr.CustomFormat.Processors.PersistenceSteps
[Parallelizable(ParallelScope.All)]
public class QualityProfileApiPersistenceStepTest
{
[Test]
public void Do_not_invoke_api_if_no_scores_to_update()
{
const string radarrQualityProfileData = @"[{
'name': 'profile1',
'formatItems': [{
'format': 1,
'name': 'cf1',
'score': 1
},
{
'format': 2,
'name': 'cf2',
'score': 2
},
{
'format': 3,
'name': 'cf3',
'score': 3
}
],
'id': 1
}]";
var api = Substitute.For<IQualityProfileService>();
api.GetQualityProfiles().Returns(JsonConvert.DeserializeObject<List<JObject>>(radarrQualityProfileData));
var cfScores = new Dictionary<string, List<QualityProfileCustomFormatScoreEntry>>
{
{
"profile1", new List<QualityProfileCustomFormatScoreEntry>
{
new(new ProcessedCustomFormatData("", "", new JObject())
{
CacheEntry = new TrashIdMapping("", "") {CustomFormatId = 4}
}, 100)
}
}
};
var processor = new QualityProfileApiPersistenceStep();
processor.Process(api, cfScores);
api.DidNotReceive().UpdateQualityProfile(Arg.Any<JObject>(), Arg.Any<int>());
}
[Test]
public void Invalid_quality_profile_names_are_reported()
{

@ -54,6 +54,12 @@ namespace Trash.Radarr.CustomFormat.Processors.PersistenceSteps
_updatedScores.GetOrCreate(profileName).Add(score);
}
if (!_updatedScores.TryGetValue(profileName, out var updatedScores) || updatedScores.Count == 0)
{
// No scores to update, so don't bother with the API call
continue;
}
var jsonRoot = (JObject) jsonList.First().Root;
await api.UpdateQualityProfile(jsonRoot, (int) jsonRoot["id"]);
}

Loading…
Cancel
Save