From 62f6670a212b282a42beab2aa6ec407473d9bf1e Mon Sep 17 00:00:00 2001 From: Qstick Date: Thu, 20 Jan 2022 23:19:58 -0600 Subject: [PATCH] Optimize Indexer updates --- .../IndexerDefinitionUpdateService.cs | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/NzbDrone.Core/IndexerVersions/IndexerDefinitionUpdateService.cs b/src/NzbDrone.Core/IndexerVersions/IndexerDefinitionUpdateService.cs index dc4c6f2e7..be38c301b 100644 --- a/src/NzbDrone.Core/IndexerVersions/IndexerDefinitionUpdateService.cs +++ b/src/NzbDrone.Core/IndexerVersions/IndexerDefinitionUpdateService.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.IO.Compression; using System.Linq; using NLog; using NzbDrone.Common.Cache; @@ -26,6 +27,7 @@ namespace NzbDrone.Core.IndexerVersions { /* Update Service will fall back if version # does not exist for an indexer per Ta */ + private const string DEFINITION_BRANCH = "master"; private const int DEFINITION_VERSION = 3; private readonly List _defintionBlocklist = new List() { @@ -76,7 +78,7 @@ namespace NzbDrone.Core.IndexerVersions try { - var request = new HttpRequest($"https://indexers.prowlarr.com/master/{DEFINITION_VERSION}"); + var request = new HttpRequest($"https://indexers.prowlarr.com/{DEFINITION_BRANCH}/{DEFINITION_VERSION}"); var response = _httpClient.Get>(request); indexerList = response.Resource.Where(i => !_defintionBlocklist.Contains(i.File)).ToList(); @@ -141,7 +143,7 @@ namespace NzbDrone.Core.IndexerVersions private CardigannDefinition GetHttpDefinition(string id) { - var req = new HttpRequest($"https://indexers.prowlarr.com/master/{DEFINITION_VERSION}/{id}"); + var req = new HttpRequest($"https://indexers.prowlarr.com/{DEFINITION_BRANCH}/{DEFINITION_VERSION}/{id}"); var response = _httpClient.Get(req); var definition = _deserializer.Deserialize(response.Content); return CleanIndexerDefinition(definition); @@ -238,29 +240,31 @@ namespace NzbDrone.Core.IndexerVersions private void UpdateLocalDefinitions() { - var request = new HttpRequest($"https://indexers.prowlarr.com/master/{DEFINITION_VERSION}"); - var response = _httpClient.Get>(request); + var startupFolder = _appFolderInfo.AppDataFolder; - foreach (var def in response.Resource) + try { - try - { - var startupFolder = _appFolderInfo.AppDataFolder; - - EnsureDefinitionsFolder(); + EnsureDefinitionsFolder(); - var saveFile = Path.Combine(startupFolder, "Definitions", $"{def.File}.yml"); + var definitionsFolder = Path.Combine(startupFolder, "Definitions"); + var saveFile = Path.Combine(startupFolder, "Definitions", $"indexers.zip"); - _httpClient.DownloadFile($"https://indexers.prowlarr.com/master/{DEFINITION_VERSION}/{def.File}", saveFile); + _httpClient.DownloadFile($"https://indexers.prowlarr.com/{DEFINITION_BRANCH}/{DEFINITION_VERSION}/package.zip", saveFile); - _cache.Remove(def.File); - - _logger.Debug("Updated definition: {0}", def.File); - } - catch (Exception ex) + using (ZipArchive archive = ZipFile.OpenRead(saveFile)) { - _logger.Error("Definition download failed: {0}, {1}", def.File, ex.Message); + archive.ExtractToDirectory(definitionsFolder, true); } + + _diskProvider.DeleteFile(saveFile); + + _cache.Clear(); + + _logger.Debug("Updated indexer definitions"); + } + catch (Exception ex) + { + _logger.Error(ex, "Definition update failed"); } } }