refactor: Reduce cognitive complexity of method

pull/201/head
Robert Dailey 2 years ago
parent 134477ab46
commit 3c5b139523

@ -67,7 +67,6 @@ public class CustomFormatSyncPipeline : ISyncPipeline
return; return;
} }
// todo: Update the ProcessedCustomFormat objects' FormatId after API calls
await _phases.ApiPersistencePhase.Execute(config, transactions); await _phases.ApiPersistencePhase.Execute(config, transactions);
_cachePersister.Save(config, cache.Update(guideCfs)); _cachePersister.Save(config, cache.Update(guideCfs));

@ -33,6 +33,39 @@ public class CustomFormatTransactionPhase
var serviceCf = FindServiceCfByName(serviceData, guideCf.Name); var serviceCf = FindServiceCfByName(serviceData, guideCf.Name);
if (serviceCf is not null) if (serviceCf is not null)
{
ProcessExistingCf(config, guideCf, serviceCf, transactions);
continue;
}
serviceCf = FindServiceCfById(serviceData, guideCf.Id);
if (serviceCf is not null)
{
// We do not use AddUpdatedCustomFormat() here because it's impossible for the CFs to be identical if we
// got to this point. Reason: We reach this code if the names are not the same. At the very least, this
// means the name needs to be updated in the service.
transactions.UpdatedCustomFormats.Add(guideCf);
}
else
{
transactions.NewCustomFormats.Add(guideCf);
}
}
transactions.DeletedCustomFormats.AddRange(cache.TrashIdMappings
// Custom format must be in the cache but NOT in the user's config
.Where(map => guideCfs.All(cf => cf.TrashId != map.TrashId))
// Also, that cache-only CF must exist in the service (otherwise there is nothing to delete)
.Where(map => serviceData.Any(cf => cf.Id == map.CustomFormatId)));
return transactions;
}
private void ProcessExistingCf(
IServiceConfiguration config,
CustomFormatData guideCf,
CustomFormatData serviceCf,
CustomFormatTransactionData transactions)
{ {
if (config.ReplaceExistingCustomFormats) if (config.ReplaceExistingCustomFormats)
{ {
@ -64,31 +97,6 @@ public class CustomFormatTransactionPhase
AddUpdatedCustomFormat(guideCf, serviceCf, transactions); AddUpdatedCustomFormat(guideCf, serviceCf, transactions);
} }
} }
continue;
}
serviceCf = FindServiceCfById(serviceData, guideCf.Id);
if (serviceCf is not null)
{
// We do not use AddUpdatedCustomFormat() here because it's impossible for the CFs to be identical if we
// got to this point. Reason: We reach this code if the names are not the same. At the very least, this
// means the name needs to be updated in the service.
transactions.UpdatedCustomFormats.Add(guideCf);
}
else
{
transactions.NewCustomFormats.Add(guideCf);
}
}
transactions.DeletedCustomFormats.AddRange(cache.TrashIdMappings
// Custom format must be in the cache but NOT in the user's config
.Where(map => guideCfs.All(cf => cf.TrashId != map.TrashId))
// Also, that cache-only CF must exist in the service (otherwise there is nothing to delete)
.Where(map => serviceData.Any(cf => cf.Id == map.CustomFormatId)));
return transactions;
} }
private static void AddUpdatedCustomFormat( private static void AddUpdatedCustomFormat(

Loading…
Cancel
Save