Don't retest unchanged providers
New: Don't retest connections, indexers, download clients, etc if re-saved with the exact same settings Closes #6169
This commit is contained in:
parent
c7d12066bf
commit
71fd09f162
|
@ -1,4 +1,5 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
using NzbDrone.Core.Datastore;
|
using NzbDrone.Core.Datastore;
|
||||||
|
|
||||||
namespace NzbDrone.Core.ThingiProvider
|
namespace NzbDrone.Core.ThingiProvider
|
||||||
|
@ -13,7 +14,10 @@ namespace NzbDrone.Core.ThingiProvider
|
||||||
private IProviderConfig _settings;
|
private IProviderConfig _settings;
|
||||||
|
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
public string ImplementationName { get; set; }
|
public string ImplementationName { get; set; }
|
||||||
|
|
||||||
public string Implementation { get; set; }
|
public string Implementation { get; set; }
|
||||||
public string ConfigContract { get; set; }
|
public string ConfigContract { get; set; }
|
||||||
public virtual bool Enable { get; set; }
|
public virtual bool Enable { get; set; }
|
||||||
|
|
|
@ -70,7 +70,7 @@ namespace Sonarr.Api.V3
|
||||||
[Produces("application/json")]
|
[Produces("application/json")]
|
||||||
public ActionResult<TProviderResource> CreateProvider([FromBody] TProviderResource providerResource, [FromQuery] bool forceSave = false)
|
public ActionResult<TProviderResource> CreateProvider([FromBody] TProviderResource providerResource, [FromQuery] bool forceSave = false)
|
||||||
{
|
{
|
||||||
var providerDefinition = GetDefinition(providerResource, true, !forceSave, false);
|
var providerDefinition = GetDefinition(providerResource, null, true, !forceSave, false);
|
||||||
|
|
||||||
if (providerDefinition.Enable)
|
if (providerDefinition.Enable)
|
||||||
{
|
{
|
||||||
|
@ -87,15 +87,22 @@ namespace Sonarr.Api.V3
|
||||||
[Produces("application/json")]
|
[Produces("application/json")]
|
||||||
public ActionResult<TProviderResource> UpdateProvider([FromBody] TProviderResource providerResource, [FromQuery] bool forceSave = false)
|
public ActionResult<TProviderResource> UpdateProvider([FromBody] TProviderResource providerResource, [FromQuery] bool forceSave = false)
|
||||||
{
|
{
|
||||||
var providerDefinition = GetDefinition(providerResource, true, !forceSave, false);
|
var existingDefinition = _providerFactory.Find(providerResource.Id);
|
||||||
|
var providerDefinition = GetDefinition(providerResource, existingDefinition, true, !forceSave, false);
|
||||||
|
|
||||||
// Only test existing definitions if it is enabled and forceSave isn't set.
|
// Comparing via JSON string to eliminate the need for every provider implementation to implement equality checks.
|
||||||
if (providerDefinition.Enable && !forceSave)
|
var hasDefinitionChanged = STJson.ToJson(existingDefinition) != STJson.ToJson(providerDefinition);
|
||||||
|
|
||||||
|
// Only test existing definitions if it is enabled and forceSave isn't set or the definition has changed.
|
||||||
|
if (providerDefinition.Enable && (!forceSave || hasDefinitionChanged))
|
||||||
{
|
{
|
||||||
Test(providerDefinition, true);
|
Test(providerDefinition, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hasDefinitionChanged)
|
||||||
|
{
|
||||||
_providerFactory.Update(providerDefinition);
|
_providerFactory.Update(providerDefinition);
|
||||||
|
}
|
||||||
|
|
||||||
return Accepted(providerResource.Id);
|
return Accepted(providerResource.Id);
|
||||||
}
|
}
|
||||||
|
@ -141,9 +148,8 @@ namespace Sonarr.Api.V3
|
||||||
return Accepted(_providerFactory.Update(definitionsToUpdate).Select(x => _resourceMapper.ToResource(x)));
|
return Accepted(_providerFactory.Update(definitionsToUpdate).Select(x => _resourceMapper.ToResource(x)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private TProviderDefinition GetDefinition(TProviderResource providerResource, bool validate, bool includeWarnings, bool forceValidate)
|
private TProviderDefinition GetDefinition(TProviderResource providerResource, TProviderDefinition existingDefinition, bool validate, bool includeWarnings, bool forceValidate)
|
||||||
{
|
{
|
||||||
var existingDefinition = providerResource.Id > 0 ? _providerFactory.Find(providerResource.Id) : null;
|
|
||||||
var definition = _resourceMapper.ToModel(providerResource, existingDefinition);
|
var definition = _resourceMapper.ToModel(providerResource, existingDefinition);
|
||||||
|
|
||||||
if (validate && (definition.Enable || forceValidate))
|
if (validate && (definition.Enable || forceValidate))
|
||||||
|
@ -199,7 +205,8 @@ namespace Sonarr.Api.V3
|
||||||
[Consumes("application/json")]
|
[Consumes("application/json")]
|
||||||
public object Test([FromBody] TProviderResource providerResource)
|
public object Test([FromBody] TProviderResource providerResource)
|
||||||
{
|
{
|
||||||
var providerDefinition = GetDefinition(providerResource, true, true, true);
|
var existingDefinition = providerResource.Id > 0 ? _providerFactory.Find(providerResource.Id) : null;
|
||||||
|
var providerDefinition = GetDefinition(providerResource, existingDefinition, true, true, true);
|
||||||
|
|
||||||
Test(providerDefinition, true);
|
Test(providerDefinition, true);
|
||||||
|
|
||||||
|
@ -236,9 +243,10 @@ namespace Sonarr.Api.V3
|
||||||
[HttpPost("action/{name}")]
|
[HttpPost("action/{name}")]
|
||||||
[Consumes("application/json")]
|
[Consumes("application/json")]
|
||||||
[Produces("application/json")]
|
[Produces("application/json")]
|
||||||
public IActionResult RequestAction(string name, [FromBody] TProviderResource resource)
|
public IActionResult RequestAction(string name, [FromBody] TProviderResource providerResource)
|
||||||
{
|
{
|
||||||
var providerDefinition = GetDefinition(resource, false, false, false);
|
var existingDefinition = providerResource.Id > 0 ? _providerFactory.Find(providerResource.Id) : null;
|
||||||
|
var providerDefinition = GetDefinition(providerResource, existingDefinition, false, false, false);
|
||||||
|
|
||||||
var query = Request.Query.ToDictionary(x => x.Key, x => x.Value.ToString());
|
var query = Request.Query.ToDictionary(x => x.Key, x => x.Value.ToString());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue