From 20456fb9e73ae4d04e44caca6e9bc6ea23b496b1 Mon Sep 17 00:00:00 2001 From: Qstick Date: Sun, 21 Feb 2021 22:33:54 -0500 Subject: [PATCH] New: Cache Schema calls to avoid making them on every Indexer add --- src/NzbDrone.Core/Applications/Lidarr/Lidarr.cs | 8 ++++++-- src/NzbDrone.Core/Applications/Radarr/Radarr.cs | 8 ++++++-- src/NzbDrone.Core/Applications/Readarr/Readarr.cs | 8 ++++++-- src/NzbDrone.Core/Applications/Sonarr/Sonarr.cs | 8 ++++++-- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/NzbDrone.Core/Applications/Lidarr/Lidarr.cs b/src/NzbDrone.Core/Applications/Lidarr/Lidarr.cs index 5a2e50223..c766a9aab 100644 --- a/src/NzbDrone.Core/Applications/Lidarr/Lidarr.cs +++ b/src/NzbDrone.Core/Applications/Lidarr/Lidarr.cs @@ -3,7 +3,9 @@ using System.Collections.Generic; using System.Linq; using FluentValidation.Results; using NLog; +using NzbDrone.Common.Cache; using NzbDrone.Common.Extensions; +using NzbDrone.Common.Serializer; using NzbDrone.Core.Configuration; using NzbDrone.Core.Indexers; @@ -14,11 +16,13 @@ namespace NzbDrone.Core.Applications.Lidarr public override string Name => "Lidarr"; private readonly ILidarrV1Proxy _lidarrV1Proxy; + private readonly ICached> _schemaCache; private readonly IConfigFileProvider _configFileProvider; - public Lidarr(ILidarrV1Proxy lidarrV1Proxy, IConfigFileProvider configFileProvider, IAppIndexerMapService appIndexerMapService, Logger logger) + public Lidarr(ICacheManager cacheManager, ILidarrV1Proxy lidarrV1Proxy, IConfigFileProvider configFileProvider, IAppIndexerMapService appIndexerMapService, Logger logger) : base(appIndexerMapService, logger) { + _schemaCache = cacheManager.GetCache>(GetType()); _lidarrV1Proxy = lidarrV1Proxy; _configFileProvider = configFileProvider; } @@ -34,7 +38,7 @@ namespace NzbDrone.Core.Applications.Lidarr public override void AddIndexer(IndexerDefinition indexer) { - var schema = _lidarrV1Proxy.GetIndexerSchema(Settings); + var schema = _schemaCache.Get(Definition.Settings.ToJson(), () => _lidarrV1Proxy.GetIndexerSchema(Settings), TimeSpan.FromDays(7)); var newznab = schema.Where(i => i.Implementation == "Newznab").First(); var torznab = schema.Where(i => i.Implementation == "Torznab").First(); diff --git a/src/NzbDrone.Core/Applications/Radarr/Radarr.cs b/src/NzbDrone.Core/Applications/Radarr/Radarr.cs index 2d6787fe4..38db98428 100644 --- a/src/NzbDrone.Core/Applications/Radarr/Radarr.cs +++ b/src/NzbDrone.Core/Applications/Radarr/Radarr.cs @@ -3,7 +3,9 @@ using System.Collections.Generic; using System.Linq; using FluentValidation.Results; using NLog; +using NzbDrone.Common.Cache; using NzbDrone.Common.Extensions; +using NzbDrone.Common.Serializer; using NzbDrone.Core.Configuration; using NzbDrone.Core.Indexers; @@ -14,11 +16,13 @@ namespace NzbDrone.Core.Applications.Radarr public override string Name => "Radarr"; private readonly IRadarrV3Proxy _radarrV3Proxy; + private readonly ICached> _schemaCache; private readonly IConfigFileProvider _configFileProvider; - public Radarr(IRadarrV3Proxy radarrV3Proxy, IConfigFileProvider configFileProvider, IAppIndexerMapService appIndexerMapService, Logger logger) + public Radarr(ICacheManager cacheManager, IRadarrV3Proxy radarrV3Proxy, IConfigFileProvider configFileProvider, IAppIndexerMapService appIndexerMapService, Logger logger) : base(appIndexerMapService, logger) { + _schemaCache = cacheManager.GetCache>(GetType()); _radarrV3Proxy = radarrV3Proxy; _configFileProvider = configFileProvider; } @@ -34,7 +38,7 @@ namespace NzbDrone.Core.Applications.Radarr public override void AddIndexer(IndexerDefinition indexer) { - var schema = _radarrV3Proxy.GetIndexerSchema(Settings); + var schema = _schemaCache.Get(Definition.Settings.ToJson(), () => _radarrV3Proxy.GetIndexerSchema(Settings), TimeSpan.FromDays(7)); var newznab = schema.Where(i => i.Implementation == "Newznab").First(); var torznab = schema.Where(i => i.Implementation == "Torznab").First(); diff --git a/src/NzbDrone.Core/Applications/Readarr/Readarr.cs b/src/NzbDrone.Core/Applications/Readarr/Readarr.cs index 11da039f6..e9dffdd94 100644 --- a/src/NzbDrone.Core/Applications/Readarr/Readarr.cs +++ b/src/NzbDrone.Core/Applications/Readarr/Readarr.cs @@ -3,7 +3,9 @@ using System.Collections.Generic; using System.Linq; using FluentValidation.Results; using NLog; +using NzbDrone.Common.Cache; using NzbDrone.Common.Extensions; +using NzbDrone.Common.Serializer; using NzbDrone.Core.Configuration; using NzbDrone.Core.Indexers; @@ -13,12 +15,14 @@ namespace NzbDrone.Core.Applications.Readarr { public override string Name => "Readarr"; + private readonly ICached> _schemaCache; private readonly IReadarrV1Proxy _readarrV1Proxy; private readonly IConfigFileProvider _configFileProvider; - public Readarr(IReadarrV1Proxy readarrV1Proxy, IConfigFileProvider configFileProvider, IAppIndexerMapService appIndexerMapService, Logger logger) + public Readarr(ICacheManager cacheManager, IReadarrV1Proxy readarrV1Proxy, IConfigFileProvider configFileProvider, IAppIndexerMapService appIndexerMapService, Logger logger) : base(appIndexerMapService, logger) { + _schemaCache = cacheManager.GetCache>(GetType()); _readarrV1Proxy = readarrV1Proxy; _configFileProvider = configFileProvider; } @@ -34,7 +38,7 @@ namespace NzbDrone.Core.Applications.Readarr public override void AddIndexer(IndexerDefinition indexer) { - var schema = _readarrV1Proxy.GetIndexerSchema(Settings); + var schema = _schemaCache.Get(Definition.Settings.ToJson(), () => _readarrV1Proxy.GetIndexerSchema(Settings), TimeSpan.FromDays(7)); var newznab = schema.Where(i => i.Implementation == "Newznab").First(); var torznab = schema.Where(i => i.Implementation == "Torznab").First(); diff --git a/src/NzbDrone.Core/Applications/Sonarr/Sonarr.cs b/src/NzbDrone.Core/Applications/Sonarr/Sonarr.cs index 4123e05ff..cdc9506c9 100644 --- a/src/NzbDrone.Core/Applications/Sonarr/Sonarr.cs +++ b/src/NzbDrone.Core/Applications/Sonarr/Sonarr.cs @@ -3,7 +3,9 @@ using System.Collections.Generic; using System.Linq; using FluentValidation.Results; using NLog; +using NzbDrone.Common.Cache; using NzbDrone.Common.Extensions; +using NzbDrone.Common.Serializer; using NzbDrone.Core.Configuration; using NzbDrone.Core.Indexers; @@ -13,12 +15,14 @@ namespace NzbDrone.Core.Applications.Sonarr { public override string Name => "Sonarr"; + private readonly ICached> _schemaCache; private readonly ISonarrV3Proxy _sonarrV3Proxy; private readonly IConfigFileProvider _configFileProvider; - public Sonarr(ISonarrV3Proxy sonarrV3Proxy, IConfigFileProvider configFileProvider, IAppIndexerMapService appIndexerMapService, Logger logger) + public Sonarr(ICacheManager cacheManager, ISonarrV3Proxy sonarrV3Proxy, IConfigFileProvider configFileProvider, IAppIndexerMapService appIndexerMapService, Logger logger) : base(appIndexerMapService, logger) { + _schemaCache = cacheManager.GetCache>(GetType()); _sonarrV3Proxy = sonarrV3Proxy; _configFileProvider = configFileProvider; } @@ -34,7 +38,7 @@ namespace NzbDrone.Core.Applications.Sonarr public override void AddIndexer(IndexerDefinition indexer) { - var schema = _sonarrV3Proxy.GetIndexerSchema(Settings); + var schema = _schemaCache.Get(Definition.Settings.ToJson(), () => _sonarrV3Proxy.GetIndexerSchema(Settings), TimeSpan.FromDays(7)); var newznab = schema.Where(i => i.Implementation == "Newznab").First(); var torznab = schema.Where(i => i.Implementation == "Torznab").First();