From 6f55c81d5ba64440b320ee461a31d141b6e33ae4 Mon Sep 17 00:00:00 2001 From: Robbie Davis Date: Wed, 14 Jan 2026 00:09:20 -0500 Subject: [PATCH] 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. --- .../Applications/Listenarr/Listenarr.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/NzbDrone.Core/Applications/Listenarr/Listenarr.cs b/src/NzbDrone.Core/Applications/Listenarr/Listenarr.cs index a10417e61..c591df5f3 100644 --- a/src/NzbDrone.Core/Applications/Listenarr/Listenarr.cs +++ b/src/NzbDrone.Core/Applications/Listenarr/Listenarr.cs @@ -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)