mirror of
https://github.com/Prowlarr/Prowlarr
synced 2026-05-09 05:22:09 +02:00
Prevent duplicate remote indexer mappings
Before adding a new remote indexer, check for existing indexers with matching baseUrl or name. If found, insert a mapping and skip adding to avoid duplicates. Logs errors encountered during the check.
This commit is contained in:
parent
af4bcbc879
commit
6f55c81d5b
1 changed files with 22 additions and 0 deletions
|
|
@ -142,6 +142,28 @@ public override void AddIndexer(IndexerDefinition indexer)
|
|||
|
||||
var listenarrIndexer = BuildListenarrIndexer(indexer, indexerCapabilities, indexer.Protocol);
|
||||
|
||||
// If an existing remote indexer already points to this app indexer (matching baseUrl or name), insert mapping and skip adding
|
||||
try
|
||||
{
|
||||
var remoteIndexers = _listenarrV1Proxy.GetIndexers(Settings);
|
||||
var baseUrl = $"{Settings.ProwlarrUrl.TrimEnd('/')}/{indexer.Id}/";
|
||||
|
||||
var match = remoteIndexers.FirstOrDefault(r =>
|
||||
((string)r.Fields.FirstOrDefault(f => f.Name == "baseUrl")?.Value ?? "").Equals(baseUrl, StringComparison.InvariantCultureIgnoreCase)
|
||||
|| (r.Name?.Contains(indexer.Name, StringComparison.InvariantCultureIgnoreCase) == true));
|
||||
|
||||
if (match != null)
|
||||
{
|
||||
_logger.Debug("Found existing remote indexer for {0} as {1} [{2}], inserting mapping", indexer.Name, match.Name, match.Id);
|
||||
_appIndexerMapService.Insert(new AppIndexerMap { AppId = Definition.Id, IndexerId = indexer.Id, RemoteIndexerId = match.Id });
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Warn(ex, "Error while attempting to discover existing remote indexer for {0} [{1}]", indexer.Name, indexer.Id);
|
||||
}
|
||||
|
||||
var remoteIndexer = _listenarrV1Proxy.AddIndexer(listenarrIndexer, Settings);
|
||||
|
||||
if (remoteIndexer == null)
|
||||
|
|
|
|||
Loading…
Reference in a new issue