fix v14
This commit is contained in:
@@ -27,6 +27,8 @@ const (
|
||||
abuseAlertThreshold24h = 8
|
||||
abuseAlertThreshold7d = 20
|
||||
abuseAlertCooldown = 24 * time.Hour
|
||||
// abuseAlertCooldownMaxEntries 冷却表的清理阈值(超过即回收已过期的条目)。
|
||||
abuseAlertCooldownMaxEntries = 1024
|
||||
)
|
||||
|
||||
// abuseAlertCooldowns 每个箱主上次发送阈值告警的时间。
|
||||
@@ -46,6 +48,17 @@ func allowAbuseAlert(userID uint) bool {
|
||||
return false
|
||||
}
|
||||
abuseAlertCooldowns[userID] = time.Now()
|
||||
|
||||
// 惰性清理:条目数超过阈值时删掉已经过冷却窗口的历史项。
|
||||
// 没有这一步这个 map 只增不减(每个箱主一个时间戳,量不大但没有任何回收路径)。
|
||||
if len(abuseAlertCooldowns) > abuseAlertCooldownMaxEntries {
|
||||
now := time.Now()
|
||||
for id, last := range abuseAlertCooldowns {
|
||||
if now.Sub(last) >= abuseAlertCooldown {
|
||||
delete(abuseAlertCooldowns, id)
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user