From 3d68a8d7ac530a91fb9b66e05a55429ec9dd3ec8 Mon Sep 17 00:00:00 2001 From: Magnus Ellinge Date: Fri, 10 Feb 2023 14:30:07 +0100 Subject: [PATCH] Same logic for diff as in LogRequests --- .../Core/Suggestions/RequestLogger.cs | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Geta.NotFoundHandler/Core/Suggestions/RequestLogger.cs b/src/Geta.NotFoundHandler/Core/Suggestions/RequestLogger.cs index 2a89421..0583d8a 100644 --- a/src/Geta.NotFoundHandler/Core/Suggestions/RequestLogger.cs +++ b/src/Geta.NotFoundHandler/Core/Suggestions/RequestLogger.cs @@ -56,13 +56,6 @@ public void LogRequest(string oldUrl, string referer) LogQueue.Enqueue(new LogEvent(oldUrl, DateTime.UtcNow, referer)); } - private bool AllowLogOfRequests() - { - var bufferSize = _configuration.BufferSize; - var threshold = _configuration.ThreshHold; - return !LogQueue.IsEmpty && ((threshold > 0 && (DateTime.UtcNow - LogQueue.Last().Requested).TotalSeconds >= threshold) || LogQueue.Count >= bufferSize); - } - private void LogRequests(ConcurrentQueue logEvents) { _logger.LogDebug("Logging 404 errors to database"); @@ -93,6 +86,19 @@ private void LogRequests(ConcurrentQueue logEvents) } } + private bool AllowLogOfRequests() + { + if (LogQueue.IsEmpty) + return false; + + var bufferSize = _configuration.BufferSize; + var threshold = _configuration.ThreshHold; + if (threshold > 0 && bufferSize > 0 && (bufferSize / (DateTime.UtcNow - LogQueue.Last().Requested).TotalSeconds) <= threshold) + return true; + + return LogQueue.Count >= bufferSize; + } + private static bool IgnoreSuggestion(LogEvent logEvent, IEnumerable ignored) { if (logEvent.OldUrl.StartsWith("/EPiServer/", StringComparison.InvariantCultureIgnoreCase))