From b3656077149ce3b03c4389a9fc4627e41c5f43f3 Mon Sep 17 00:00:00 2001 From: Diego Heras Date: Mon, 14 Dec 2020 00:46:18 +0100 Subject: [PATCH] core: improve search cache debug logs (#10502) --- src/Jackett.Common/Services/CacheService.cs | 24 +++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Jackett.Common/Services/CacheService.cs b/src/Jackett.Common/Services/CacheService.cs index 8ef77978a..dac9101ef 100644 --- a/src/Jackett.Common/Services/CacheService.cs +++ b/src/Jackett.Common/Services/CacheService.cs @@ -97,12 +97,17 @@ namespace Jackett.Common.Services var trackerCache = _cache[indexer.Id]; var queryHash = GetQueryHash(query); - if (!trackerCache.Queries.ContainsKey(queryHash)) + var cacheHit = trackerCache.Queries.ContainsKey(queryHash); + + if (_logger.IsDebugEnabled) + _logger.Debug($"CACHE Search / Indexer: {trackerCache.TrackerId} / CacheHit: {cacheHit} / Query: {GetSerializedQuery(query)}"); + + if (!cacheHit) return null; var releases = trackerCache.Queries[queryHash].Results; - _logger.Debug($"CACHE Search / Indexer: {trackerCache.TrackerId} / Found: {releases.Count} releases"); - + _logger.Debug($"CACHE Search Hit / Indexer: {trackerCache.TrackerId} / Found: {releases.Count} releases"); + return releases; } } @@ -231,14 +236,21 @@ namespace Jackett.Common.Services } private string GetQueryHash(TorznabQuery query) + { + var json = GetSerializedQuery(query); + // Compute the hash + return BitConverter.ToString(_sha256.ComputeHash(Encoding.ASCII.GetBytes(json))); + } + + private static string GetSerializedQuery(TorznabQuery query) { var json = Newtonsoft.Json.JsonConvert.SerializeObject(query); - _logger.Debug($"CACHE Request query: {json}"); + // Changes in the query to improve cache hits // Both request must return the same results, if not we are breaking Jackett search json = json.Replace("\"SearchTerm\":null", "\"SearchTerm\":\"\""); - // Compute the hash - return BitConverter.ToString(_sha256.ComputeHash(Encoding.ASCII.GetBytes(json))); + + return json; } private void PrintCacheStatus()