fix(radarr): set scores for unchanged custom formats

recyclarr
Robert Dailey 3 years ago
parent 00ed14f55c
commit 50195b8cfd

@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Invalid cache data files no longer cause the program to exit. An error is printed and the - Invalid cache data files no longer cause the program to exit. An error is printed and the
application continues as if there was no cache at all. application continues as if there was no cache at all.
- Fix a bug that resulted in certain custom formats not having their scores set in quality
profiles.
### Changed ### Changed

@ -100,7 +100,7 @@ namespace Trash.Tests.Radarr.CustomFormat.Processors.PersistenceSteps
} }
[Test] [Test]
public void Combination_of_create_update_and_no_change_and_verify_proper_json_merging() public void Combination_of_create_update_and_unchanged_and_verify_proper_json_merging()
{ {
const string radarrCfData = @"[{ const string radarrCfData = @"[{
'id': 1, 'id': 1,
@ -178,7 +178,7 @@ namespace Trash.Tests.Radarr.CustomFormat.Processors.PersistenceSteps
new("created", "", guideCfData[0]), new("created", "", guideCfData[0]),
new("updated_different_name", "", guideCfData[1]) new("updated_different_name", "", guideCfData[1])
{ {
CacheEntry = new TrashIdMapping("", "") {CustomFormatId = 2} CacheEntry = new TrashIdMapping("", "", 2)
}, },
new("no_change", "", guideCfData[2]) new("no_change", "", guideCfData[2])
}; };
@ -362,5 +362,66 @@ namespace Trash.Tests.Radarr.CustomFormat.Processors.PersistenceSteps
expectedTransactions.DeletedCustomFormatIds.Add(new TrashIdMapping("testtrashid", "testname", 2)); expectedTransactions.DeletedCustomFormatIds.Add(new TrashIdMapping("testtrashid", "testname", 2));
processor.Transactions.Should().BeEquivalentTo(expectedTransactions); processor.Transactions.Should().BeEquivalentTo(expectedTransactions);
} }
[Test]
public void Updated_and_unchanged_custom_formats_have_cache_entry_set_when_there_is_no_cache()
{
const string radarrCfData = @"[{
'id': 1,
'name': 'updated',
'specifications': [{
'name': 'spec2',
'fields': [{
'name': 'value',
'value': 'value1'
}]
}]
}, {
'id': 2,
'name': 'no_change',
'specifications': [{
'name': 'spec4',
'negate': false,
'fields': [{
'name': 'value',
'value': 'value1'
}]
}]
}]";
var guideCfData = JsonConvert.DeserializeObject<List<JObject>>(@"[{
'name': 'updated',
'specifications': [{
'name': 'spec2',
'fields': {
'value': 'value2'
}
}]
}, {
'name': 'no_change',
'specifications': [{
'name': 'spec4',
'negate': false,
'fields': {
'value': 'value1'
}
}]
}]");
var radarrCfs = JsonConvert.DeserializeObject<List<JObject>>(radarrCfData);
var guideCfs = new List<ProcessedCustomFormatData>
{
new("updated", "", guideCfData[0]),
new("no_change", "", guideCfData[1])
};
var processor = new JsonTransactionStep();
processor.Process(guideCfs, radarrCfs);
processor.Transactions.UpdatedCustomFormats.First().CacheEntry.Should()
.BeEquivalentTo(new TrashIdMapping("", "updated", 1));
processor.Transactions.UnchangedCustomFormats.First().CacheEntry.Should()
.BeEquivalentTo(new TrashIdMapping("", "no_change", 2));
}
} }
} }

@ -36,13 +36,6 @@ namespace Trash.Radarr.CustomFormat.Api
public async Task UpdateCustomFormat(ProcessedCustomFormatData cf) public async Task UpdateCustomFormat(ProcessedCustomFormatData cf)
{ {
// Set the cache first, since it's needed to perform the update. This case will apply to CFs we update that
// exist in Radarr but not the cache (e.g. moving to a new machine, same-named CF was created manually)
if (cf.CacheEntry == null)
{
cf.SetCache((int) cf.Json["id"]);
}
await BaseUrl() await BaseUrl()
.AppendPathSegment($"customformat/{cf.GetCustomFormatId()}") .AppendPathSegment($"customformat/{cf.GetCustomFormatId()}")
.PutJsonAsync(cf.Json) .PutJsonAsync(cf.Json)

@ -39,6 +39,14 @@ namespace Trash.Radarr.CustomFormat.Processors.PersistenceSteps
guideCf.Json = (JObject) radarrCf.DeepClone(); guideCf.Json = (JObject) radarrCf.DeepClone();
UpdateRadarrCf(guideCf.Json, guideCfJson); UpdateRadarrCf(guideCf.Json, guideCfJson);
// Set the cache for use later (like updating scores) if it hasn't been updated already.
// This handles CFs that already exist in Radarr but aren't cached (they will be added to cache
// later).
if (guideCf.CacheEntry == null)
{
guideCf.SetCache((int) guideCf.Json["id"]);
}
if (!JToken.DeepEquals(radarrCf, guideCf.Json)) if (!JToken.DeepEquals(radarrCf, guideCf.Json))
{ {
Transactions.UpdatedCustomFormats.Add(guideCf); Transactions.UpdatedCustomFormats.Add(guideCf);

Loading…
Cancel
Save