feat: Re-introduce the CF name field in cache for display purposes

The CF name in cache is needed when printing information about deleted
CFs to console output.
snyk
Robert Dailey 1 year ago
parent 8023f7f011
commit 0830d1d6c8

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="JsonStandardCompliance" enabled="false" level="ERROR" enabled_by_default="false" />
</profile>
</component>

@ -168,7 +168,7 @@ public class ServiceCacheTest
}
[Test, AutoMockData]
public void Name_properties_get_truncated_on_load(
public void Name_properties_are_set_on_load(
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
[Frozen] ICacheStoragePath storage,
ServiceCache sut)
@ -195,7 +195,7 @@ public class ServiceCacheTest
{
TrashIdMappings = new Collection<TrashIdMapping>
{
new("eca37840c13c6ef2dd0262b141a5482f", 4)
new("eca37840c13c6ef2dd0262b141a5482f", "4K Remaster", 4)
}
});
}

@ -38,7 +38,7 @@ public class CachePersisterTest
var testCfObj = new CustomFormatCache
{
Version = versionToTest,
TrashIdMappings = new Collection<TrashIdMapping> {new("", 5)}
TrashIdMappings = new Collection<TrashIdMapping> {new("", "", 5)}
};
ctx.ServiceCache.Load<CustomFormatCache>().Returns(testCfObj);
ctx.Persister.Load();
@ -53,7 +53,7 @@ public class CachePersisterTest
var testCfObj = new CustomFormatCache
{
Version = CustomFormatCache.LatestVersion,
TrashIdMappings = new Collection<TrashIdMapping> {new("", 5)}
TrashIdMappings = new Collection<TrashIdMapping> {new("", "", 5)}
};
ctx.ServiceCache.Load<CustomFormatCache>().Returns(testCfObj);
ctx.Persister.Load();
@ -108,7 +108,7 @@ public class CachePersisterTest
// Load initial CfCache just to test that it gets replaced
var testCfObj = new CustomFormatCache
{
TrashIdMappings = new Collection<TrashIdMapping> {new("") {CustomFormatId = 5}}
TrashIdMappings = new Collection<TrashIdMapping> {new("", "") {CustomFormatId = 5}}
};
ctx.ServiceCache.Load<CustomFormatCache>().Returns(testCfObj);
ctx.Persister.Load();
@ -119,7 +119,7 @@ public class CachePersisterTest
var customFormatData = new List<ProcessedCustomFormatData>
{
new(NewCf.Data("", "trashid")) {CacheEntry = new TrashIdMapping("trashid", 10)}
new(NewCf.Data("", "trashid")) {CacheEntry = new TrashIdMapping("trashid", "", 10)}
};
ctx.Persister.Update(customFormatData);
@ -130,7 +130,7 @@ public class CachePersisterTest
customFormatData.Should().ContainSingle()
.Which.CacheEntry.Should().BeEquivalentTo(
new TrashIdMapping("trashid") {CustomFormatId = 10});
new TrashIdMapping("trashid", "") {CustomFormatId = 10});
}
[Test]

@ -82,13 +82,13 @@ public class CustomFormatStepTest
var testCache = new CustomFormatCache
{
TrashIdMappings = new Collection<TrashIdMapping> {new("id1000")}
TrashIdMappings = new Collection<TrashIdMapping> {new("id1000", "")}
};
processor.Process(guideData, testConfig, testCache);
processor.DeletedCustomFormatsInCache.Should()
.BeEquivalentTo(new[] {new TrashIdMapping("id1000")});
.BeEquivalentTo(new[] {new TrashIdMapping("id1000", "")});
processor.ProcessedCustomFormats.Should().BeEquivalentTo(new List<ProcessedCustomFormatData>
{
NewCf.Processed("name1", "id1")
@ -100,7 +100,7 @@ public class CustomFormatStepTest
{
var cache = new CustomFormatCache
{
TrashIdMappings = new Collection<TrashIdMapping> {new("id1", 9)}
TrashIdMappings = new Collection<TrashIdMapping> {new("id1", "", 9)}
};
var guideCfs = new List<CustomFormatData>

@ -14,7 +14,7 @@ public class CustomFormatApiPersistenceStepTest
{
private static ProcessedCustomFormatData QuickMakeCf(string cfName, string trashId, int cfId)
{
return NewCf.Processed(cfName, trashId, new TrashIdMapping(trashId) {CustomFormatId = cfId});
return NewCf.Processed(cfName, trashId, new TrashIdMapping(trashId, cfName) {CustomFormatId = cfId});
}
[Test]
@ -24,7 +24,7 @@ public class CustomFormatApiPersistenceStepTest
transactions.NewCustomFormats.Add(QuickMakeCf("cfname1", "trashid1", 1));
transactions.UpdatedCustomFormats.Add(QuickMakeCf("cfname2", "trashid2", 2));
transactions.UnchangedCustomFormats.Add(QuickMakeCf("cfname3", "trashid3", 3));
transactions.DeletedCustomFormatIds.Add(new TrashIdMapping("trashid4") {CustomFormatId = 4});
transactions.DeletedCustomFormatIds.Add(new TrashIdMapping("trashid4", "cfname4") {CustomFormatId = 4});
var api = Substitute.For<ICustomFormatService>();

@ -120,8 +120,8 @@ public class JsonTransactionStepTest
var guideCfs = new List<ProcessedCustomFormatData>
{
NewCf.Processed("created", "id1", guideCfData[0]),
NewCf.Processed("updated_different_name", "id2", guideCfData[1], new TrashIdMapping("id2", 2)),
NewCf.Processed("no_change", "id3", guideCfData[2], new TrashIdMapping("id3", 3))
NewCf.Processed("updated_different_name", "id2", guideCfData[1], new TrashIdMapping("id2", "", 2)),
NewCf.Processed("no_change", "id3", guideCfData[2], new TrashIdMapping("id3", "", 3))
};
var processor = new JsonTransactionStep();
@ -227,12 +227,12 @@ public class JsonTransactionStepTest
}");
var deletedCfsInCache = new List<TrashIdMapping>
{
new("") {CustomFormatId = 2}
new("", "") {CustomFormatId = 2}
};
var guideCfs = new List<ProcessedCustomFormatData>
{
NewCf.Processed("updated", "", guideCfData, new TrashIdMapping("") {CustomFormatId = 1})
NewCf.Processed("updated", "", guideCfData, new TrashIdMapping("", "") {CustomFormatId = 1})
};
var radarrCfs = JsonConvert.DeserializeObject<List<JObject>>(radarrCfData);
@ -253,7 +253,7 @@ public class JsonTransactionStepTest
}]
}";
var expectedTransactions = new CustomFormatTransactionData();
expectedTransactions.DeletedCustomFormatIds.Add(new TrashIdMapping("", 2));
expectedTransactions.DeletedCustomFormatIds.Add(new TrashIdMapping("", "", 2));
expectedTransactions.UpdatedCustomFormats.Add(guideCfs[0]);
processor.Transactions.Should().BeEquivalentTo(expectedTransactions);
@ -290,8 +290,8 @@ public class JsonTransactionStepTest
}]";
var deletedCfsInCache = new List<TrashIdMapping>
{
new("testtrashid", 2),
new("", 3)
new("testtrashid", "", 2),
new("", "", 3)
};
var radarrCfs = JsonConvert.DeserializeObject<List<JObject>>(radarrCfData);
@ -300,7 +300,7 @@ public class JsonTransactionStepTest
processor.RecordDeletions(deletedCfsInCache, radarrCfs!);
var expectedTransactions = new CustomFormatTransactionData();
expectedTransactions.DeletedCustomFormatIds.Add(new TrashIdMapping("testtrashid", 2));
expectedTransactions.DeletedCustomFormatIds.Add(new TrashIdMapping("testtrashid", "", 2));
processor.Transactions.Should().BeEquivalentTo(expectedTransactions);
}
}

@ -48,7 +48,7 @@ public class QualityProfileApiPersistenceStepTest
{
{
"profile1", CfTestUtils.NewMapping(new FormatMappingEntry(
NewCf.Processed("", "", new TrashIdMapping("") {CustomFormatId = 4}), 100))
NewCf.Processed("", "", new TrashIdMapping("", "") {CustomFormatId = 4}), 100))
}
};
@ -109,7 +109,7 @@ public class QualityProfileApiPersistenceStepTest
{
{
"profile1", CfTestUtils.NewMappingWithReset(
new FormatMappingEntry(NewCf.Processed("", "", new TrashIdMapping("", 2)), 100))
new FormatMappingEntry(NewCf.Processed("", "", new TrashIdMapping("", "", 2)), 100))
}
};
@ -183,11 +183,11 @@ public class QualityProfileApiPersistenceStepTest
{
"profile1", CfTestUtils.NewMapping(
// First match by ID
new FormatMappingEntry(NewCf.Processed("", "", new TrashIdMapping("", 4)), 100),
new FormatMappingEntry(NewCf.Processed("", "", new TrashIdMapping("", "", 4)), 100),
// Should NOT match because we do not use names to assign scores
new FormatMappingEntry(NewCf.Processed("", "", new TrashIdMapping("")), 101),
new FormatMappingEntry(NewCf.Processed("", "", new TrashIdMapping("", "")), 101),
// Second match by ID
new FormatMappingEntry(NewCf.Processed("", "", new TrashIdMapping("", 1)), 102))
new FormatMappingEntry(NewCf.Processed("", "", new TrashIdMapping("", "", 1)), 102))
}
};

@ -14,12 +14,14 @@ public class CustomFormatCache
public class TrashIdMapping
{
public TrashIdMapping(string trashId, int customFormatId = default)
public TrashIdMapping(string trashId, string customFormatName, int customFormatId = default)
{
TrashId = trashId;
CustomFormatName = customFormatName;
CustomFormatId = customFormatId;
}
public string TrashId { get; }
public string CustomFormatName { get; }
public int CustomFormatId { get; set; }
}

@ -22,7 +22,8 @@ public class ProcessedCustomFormatData
public void SetCache(int customFormatId)
{
CacheEntry ??= new TrashIdMapping(TrashId);
// Do not pass the customFormatId to constructor since an instance may already exist.
CacheEntry ??= new TrashIdMapping(TrashId, Name);
CacheEntry.CustomFormatId = customFormatId;
}

@ -64,8 +64,7 @@ internal class JsonTransactionStep : IJsonTransactionStep
// The 'Where' excludes cached CFs that were deleted manually by the user in Radarr
// FindRadarrCf() specifies 'null' for name because we should never delete unless an ID is found
foreach (var del in deletedCfsInCache.Where(
del => FindServiceCf(cfs, del.CustomFormatId) != null))
foreach (var del in deletedCfsInCache.Where(del => FindServiceCf(cfs, del.CustomFormatId) != null))
{
Transactions.DeletedCustomFormatIds.Add(del);
}

Loading…
Cancel
Save