1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-22 07:43:01 +00:00

Fixed: Prevent exception for seed configuration provider with invalid indexer ID

This commit is contained in:
Bogdan 2024-12-21 13:52:27 +02:00
parent ab49268bac
commit cc0d2f0142
2 changed files with 39 additions and 6 deletions

View file

@ -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<ICachedIndexerSettingsProvider>()
.Setup(v => v.GetSettings(It.IsAny<int>()))
.Returns<CachedIndexerSettings>(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

View file

@ -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<ProviderUpdatedEvent<IIndexer>>
public class CachedIndexerSettingsProvider : ICachedIndexerSettingsProvider, IHandle<ProviderUpdatedEvent<IIndexer>>, IHandle<ProviderDeletedEvent<IIndexer>>
{
private static readonly Logger Logger = NzbDroneLogger.GetLogger(typeof(CachedIndexerSettingsProvider));
private readonly IIndexerFactory _indexerFactory;
private readonly ICached<CachedIndexerSettings> _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<IIndexer> message)
{
_cache.Clear();
}
}
public class CachedIndexerSettings