From f9bc58409aa5f41b2b5bf4cdcdb2fa3c96a5e719 Mon Sep 17 00:00:00 2001 From: hoelee Date: Thu, 12 Feb 2026 14:50:00 +0800 Subject: [PATCH] feat(botfilter): add clientCache.pruneEventsLocked --- cache.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cache.go b/cache.go index 8156c16d..3c6ee786 100644 --- a/cache.go +++ b/cache.go @@ -166,3 +166,14 @@ func (c *clientCache) behaviorScoreLocked(state *clientState, paths []string) in return 0 } +func (c *clientCache) pruneEventsLocked(state *clientState, now time.Time) { + cutoff := now.Add(-c.scoreWindow) + first := 0 + for first < len(state.events) && !state.events[first].at.After(cutoff) { + first++ + } + if first > 0 { + state.events = append([]scoreEvent(nil), state.events[first:]...) + } +} +