Optimize Indexer updates

pull/801/head
Qstick 3 years ago
parent c9951e7eba
commit 62f6670a21

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.IO.Compression;
using System.Linq; using System.Linq;
using NLog; using NLog;
using NzbDrone.Common.Cache; 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 */ /* 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 const int DEFINITION_VERSION = 3;
private readonly List<string> _defintionBlocklist = new List<string>() private readonly List<string> _defintionBlocklist = new List<string>()
{ {
@ -76,7 +78,7 @@ namespace NzbDrone.Core.IndexerVersions
try 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<List<CardigannMetaDefinition>>(request); var response = _httpClient.Get<List<CardigannMetaDefinition>>(request);
indexerList = response.Resource.Where(i => !_defintionBlocklist.Contains(i.File)).ToList(); indexerList = response.Resource.Where(i => !_defintionBlocklist.Contains(i.File)).ToList();
@ -141,7 +143,7 @@ namespace NzbDrone.Core.IndexerVersions
private CardigannDefinition GetHttpDefinition(string id) 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 response = _httpClient.Get(req);
var definition = _deserializer.Deserialize<CardigannDefinition>(response.Content); var definition = _deserializer.Deserialize<CardigannDefinition>(response.Content);
return CleanIndexerDefinition(definition); return CleanIndexerDefinition(definition);
@ -238,29 +240,31 @@ namespace NzbDrone.Core.IndexerVersions
private void UpdateLocalDefinitions() private void UpdateLocalDefinitions()
{ {
var request = new HttpRequest($"https://indexers.prowlarr.com/master/{DEFINITION_VERSION}"); var startupFolder = _appFolderInfo.AppDataFolder;
var response = _httpClient.Get<List<CardigannMetaDefinition>>(request);
foreach (var def in response.Resource) try
{ {
try EnsureDefinitionsFolder();
{
var startupFolder = _appFolderInfo.AppDataFolder;
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); using (ZipArchive archive = ZipFile.OpenRead(saveFile))
_logger.Debug("Updated definition: {0}", def.File);
}
catch (Exception ex)
{ {
_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");
} }
} }
} }

Loading…
Cancel
Save