From fe3761fc2e17f3afd91cf788769ab8826cda9d0a Mon Sep 17 00:00:00 2001 From: ta264 Date: Sat, 9 Mar 2019 02:08:05 +0000 Subject: [PATCH] Cache fingerprints and relax health check (#658) --- src/NzbDrone.Core/HealthCheck/Checks/FpcalcCheck.cs | 2 +- src/NzbDrone.Core/Parser/FingerprintingService.cs | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/NzbDrone.Core/HealthCheck/Checks/FpcalcCheck.cs b/src/NzbDrone.Core/HealthCheck/Checks/FpcalcCheck.cs index 156a4946f..d90f6a0d2 100644 --- a/src/NzbDrone.Core/HealthCheck/Checks/FpcalcCheck.cs +++ b/src/NzbDrone.Core/HealthCheck/Checks/FpcalcCheck.cs @@ -32,7 +32,7 @@ namespace NzbDrone.Core.HealthCheck.Checks } var fpcalcVersion = _fingerprintingService.FpcalcVersion(); - if (fpcalcVersion == null || fpcalcVersion < new Version("1.4.3")) + if (fpcalcVersion == null || fpcalcVersion < new Version("1.2.0")) { return new HealthCheck(GetType(), HealthCheckResult.Warning, $"You have an old version of fpcalc. Please upgrade to 1.4.3.", "#fpcalc-upgrade"); } diff --git a/src/NzbDrone.Core/Parser/FingerprintingService.cs b/src/NzbDrone.Core/Parser/FingerprintingService.cs index fd3106e48..22372cd4e 100644 --- a/src/NzbDrone.Core/Parser/FingerprintingService.cs +++ b/src/NzbDrone.Core/Parser/FingerprintingService.cs @@ -14,6 +14,7 @@ using NzbDrone.Common.EnvironmentInfo; using System.Threading; using System.Text.RegularExpressions; using Newtonsoft.Json; +using NzbDrone.Common.Cache; namespace NzbDrone.Core.Parser { @@ -39,16 +40,19 @@ namespace NzbDrone.Core.Parser private readonly Logger _logger; private readonly IHttpClient _httpClient; private readonly IHttpRequestBuilderFactory _customerRequestBuilder; + private readonly ICached _cache; private readonly string _fpcalcPath; private readonly Version _fpcalcVersion; private readonly string _fpcalcArgs; public FingerprintingService(Logger logger, - IHttpClient httpClient) + IHttpClient httpClient, + ICacheManager cacheManager) { _logger = logger; _httpClient = httpClient; + _cache = cacheManager.GetCache(GetType()); _customerRequestBuilder = new HttpRequestBuilder(_acoustIdUrl).CreateFactory(); @@ -211,6 +215,11 @@ namespace NzbDrone.Core.Parser } public AcoustId GetFingerprint(string file) + { + return _cache.Get(file, () => GetFingerprintUncached(file), TimeSpan.FromMinutes(30)); + } + + private AcoustId GetFingerprintUncached(string file) { if (IsSetup() && File.Exists(file)) {