Skip to content

Commit

Permalink
Same logic for diff as in LogRequests
Browse files Browse the repository at this point in the history
  • Loading branch information
ellinge committed Feb 10, 2023
1 parent 570fe2b commit 3d68a8d
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/Geta.NotFoundHandler/Core/Suggestions/RequestLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<LogEvent> logEvents)
{
_logger.LogDebug("Logging 404 errors to database");
Expand Down Expand Up @@ -93,6 +86,19 @@ private void LogRequests(ConcurrentQueue<LogEvent> 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<string> ignored)
{
if (logEvent.OldUrl.StartsWith("/EPiServer/", StringComparison.InvariantCultureIgnoreCase))
Expand Down

0 comments on commit 3d68a8d

Please sign in to comment.