feat(botfilter): add clientCache.cleanupLocked

This commit is contained in:
hoelee committed 2026-03-02 10:22:00 +08:00
1 parent 21a4e5ad5f
commit a9f81d9735
1 file changed
+14
+14
View File
@@ -177,3 +177,17 @@ func (c *clientCache) pruneEventsLocked(state *clientState, now time.Time) {
}
}
func (c *clientCache) cleanupLocked(now time.Time) {
// Full cleanup every 256 requests amortises the map scan while retaining
// recently scored clients for the entire score window.
if c.operations%256 != 0 {
return
}
cutoff := now.Add(-c.scoreWindow)
for ip, state := range c.entries {
if !state.banUntil.After(now) && !state.lastSeen.After(cutoff) {
delete(c.entries, ip)
}
}
}