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:
parent
1d80aea02a
commit
b365607714
1 changed files with 18 additions and 6 deletions
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue