diff --git a/src/NzbDrone.Core.Test/IndexerTests/SeedConfigProviderFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/SeedConfigProviderFixture.cs index f01d50d55..0dc71467e 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/SeedConfigProviderFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/SeedConfigProviderFixture.cs @@ -22,7 +22,7 @@ namespace NzbDrone.Core.Test.IndexerTests var result = Subject.GetSeedConfiguration(new RemoteEpisode { - Release = new ReleaseInfo() + Release = new ReleaseInfo { DownloadProtocol = DownloadProtocol.Torrent, IndexerId = 0 @@ -32,6 +32,29 @@ namespace NzbDrone.Core.Test.IndexerTests result.Should().BeNull(); } + [Test] + public void should_not_return_config_for_invalid_indexer() + { + Mocker.GetMock() + .Setup(v => v.GetSettings(It.IsAny())) + .Returns(null); + + var result = Subject.GetSeedConfiguration(new RemoteEpisode + { + Release = new ReleaseInfo + { + DownloadProtocol = DownloadProtocol.Torrent, + IndexerId = 1 + }, + ParsedEpisodeInfo = new ParsedEpisodeInfo + { + FullSeason = true + } + }); + + result.Should().BeNull(); + } + [Test] public void should_return_season_time_for_season_packs() { @@ -48,7 +71,7 @@ namespace NzbDrone.Core.Test.IndexerTests var result = Subject.GetSeedConfiguration(new RemoteEpisode { - Release = new ReleaseInfo() + Release = new ReleaseInfo { DownloadProtocol = DownloadProtocol.Torrent, IndexerId = 1 diff --git a/src/NzbDrone.Core/Indexers/CachedIndexerSettingsProvider.cs b/src/NzbDrone.Core/Indexers/CachedIndexerSettingsProvider.cs index f5cb3064c..3f95ca0e4 100644 --- a/src/NzbDrone.Core/Indexers/CachedIndexerSettingsProvider.cs +++ b/src/NzbDrone.Core/Indexers/CachedIndexerSettingsProvider.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; using System.Linq; +using NLog; using NzbDrone.Common.Cache; +using NzbDrone.Common.Instrumentation; using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.ThingiProvider.Events; @@ -12,8 +14,10 @@ public interface ICachedIndexerSettingsProvider CachedIndexerSettings GetSettings(int indexerId); } -public class CachedIndexerSettingsProvider : ICachedIndexerSettingsProvider, IHandle> +public class CachedIndexerSettingsProvider : ICachedIndexerSettingsProvider, IHandle>, IHandle> { + private static readonly Logger Logger = NzbDroneLogger.GetLogger(typeof(CachedIndexerSettingsProvider)); + private readonly IIndexerFactory _indexerFactory; private readonly ICached _cache; @@ -35,11 +39,12 @@ public class CachedIndexerSettingsProvider : ICachedIndexerSettingsProvider, IHa private CachedIndexerSettings FetchIndexerSettings(int indexerId) { - var indexer = _indexerFactory.Get(indexerId); - var indexerSettings = indexer.Settings as IIndexerSettings; + var indexer = _indexerFactory.Find(indexerId); - if (indexerSettings == null) + if (indexer?.Settings is not IIndexerSettings indexerSettings) { + Logger.Trace("Could not load settings for indexer ID: {0}", indexerId); + return null; } @@ -60,6 +65,11 @@ public class CachedIndexerSettingsProvider : ICachedIndexerSettingsProvider, IHa { _cache.Clear(); } + + public void Handle(ProviderDeletedEvent message) + { + _cache.Clear(); + } } public class CachedIndexerSettings