perf: Fix trace logging of HttpClient responses from blocking the UI and pegging the CPU

This commit is contained in:
slydetector 2025-10-18 14:50:51 +00:00
parent 96e5a4df2f
commit 180c6fbe8b

View file

@ -169,7 +169,13 @@ private async Task<HttpResponse> ExecuteRequestAsync(HttpRequest request, Cookie
if (request.LogResponseContent && response.ResponseData != null)
{
_logger.Trace("Response content ({0} bytes): {1}", response.ResponseData.Length, response.Content);
// Logging large response.Content is time consuming, pegs the CPU, and blocks the UI.
// Only evaluate the Trace call when tracing is actually enabled.
// Datapoint: NZBGet history endpoint with 500 items is about 1MB and takes 2m30s to log.
if (_logger.IsTraceEnabled)
{
_logger.Trace("Response content ({0} bytes): {1}", response.ResponseData.Length, response.Content);
}
}
return response;