1
0
Fork 0
mirror of https://github.com/Jackett/Jackett synced 2025-01-01 12:46:23 +00:00

core: improve search cache debug logs (#10502)

This commit is contained in:
Diego Heras 2020-12-14 00:46:18 +01:00 committed by GitHub
parent 1d80aea02a
commit b365607714
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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()