mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-04-24 13:57:11 -04:00
Optimize Indexer updates (v2)
This commit is contained in:
parent
f56a13a375
commit
c29735741c
1 changed files with 14 additions and 32 deletions
|
@ -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;
|
||||||
|
@ -281,49 +282,30 @@ namespace NzbDrone.Core.IndexerVersions
|
||||||
private void UpdateLocalDefinitions()
|
private void UpdateLocalDefinitions()
|
||||||
{
|
{
|
||||||
var startupFolder = _appFolderInfo.AppDataFolder;
|
var startupFolder = _appFolderInfo.AppDataFolder;
|
||||||
var definitionFolder = Path.Combine(startupFolder, "Definitions");
|
|
||||||
|
|
||||||
var request = new HttpRequest($"https://indexers.prowlarr.com/{DEFINITION_BRANCH}/{DEFINITION_VERSION}");
|
|
||||||
var response = _httpClient.Get<List<CardigannMetaDefinition>>(request);
|
|
||||||
|
|
||||||
var currentDefs = _versionService.All().ToDictionary(x => x.DefinitionId, x => x.Sha);
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
EnsureDefinitionsFolder();
|
EnsureDefinitionsFolder();
|
||||||
|
|
||||||
var directoryInfo = new DirectoryInfo(definitionFolder);
|
var definitionsFolder = Path.Combine(startupFolder, "Definitions");
|
||||||
var files = directoryInfo.GetFiles($"*.yml", SearchOption.TopDirectoryOnly).Select(f => Path.GetFileNameWithoutExtension(f.Name));
|
var saveFile = Path.Combine(definitionsFolder, $"indexers.zip");
|
||||||
|
|
||||||
foreach (var def in response.Resource)
|
_httpClient.DownloadFile($"https://indexers.prowlarr.com/{DEFINITION_BRANCH}/{DEFINITION_VERSION}/package.zip", saveFile);
|
||||||
|
|
||||||
|
using (ZipArchive archive = ZipFile.OpenRead(saveFile))
|
||||||
{
|
{
|
||||||
try
|
archive.ExtractToDirectory(definitionsFolder, true);
|
||||||
{
|
|
||||||
var saveFile = Path.Combine(definitionFolder, $"{def.File}.yml");
|
|
||||||
|
|
||||||
if (currentDefs.TryGetValue(def.Id, out var defSha) && defSha == def.Sha && files.Any(x => x == def.File))
|
|
||||||
{
|
|
||||||
_logger.Trace("Indexer already up to date: {0}", def.File);
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
_httpClient.DownloadFile($"https://indexers.prowlarr.com/{DEFINITION_BRANCH}/{DEFINITION_VERSION}/{def.File}", saveFile);
|
|
||||||
|
|
||||||
_versionService.Upsert(new IndexerDefinitionVersion { Sha = def.Sha, DefinitionId = def.Id, File = def.File, LastUpdated = DateTime.UtcNow });
|
|
||||||
|
|
||||||
_cache.Remove(def.File);
|
|
||||||
_logger.Debug("Updated definition: {0}", def.File);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.Error("Definition download failed: {0}, {1}", def.File, ex.Message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_diskProvider.DeleteFile(saveFile);
|
||||||
|
|
||||||
|
_cache.Clear();
|
||||||
|
|
||||||
|
_logger.Debug("Updated indexer definitions");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.Error(ex, "Definition download failed, error creating definitions folder in {0}", startupFolder);
|
_logger.Error(ex, "Definition update failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue