refactor(acl): optimize slice allocation in logNotifyLoop

This commit is contained in:
yusing
2025-10-10 20:21:53 +08:00
parent fbabb7b7fb
commit 55a74c36b0

View File

@@ -216,18 +216,21 @@ func (c *Config) logNotifyLoop(parent task.Parent) {
if total == 0 { if total == 0 {
continue continue
} }
fieldsBody := make(notif.FieldsBody, 0, total) fieldsBody := make(notif.FieldsBody, total)
i := 0
for ip, count := range c.allowCounts { for ip, count := range c.allowCounts {
fieldsBody = append(fieldsBody, notif.LogField{ fieldsBody[i] = notif.LogField{
Name: ip, Name: ip,
Value: fmt.Sprintf("allowed %d times", count), Value: fmt.Sprintf("allowed %d times", count),
}) }
i++
} }
for ip, count := range c.blockedCounts { for ip, count := range c.blockedCounts {
fieldsBody = append(fieldsBody, notif.LogField{ fieldsBody[i] = notif.LogField{
Name: ip, Name: ip,
Value: fmt.Sprintf("blocked %d times", count), Value: fmt.Sprintf("blocked %d times", count),
}) }
i++
} }
notif.Notify(&notif.LogMessage{ notif.Notify(&notif.LogMessage{
Level: zerolog.InfoLevel, Level: zerolog.InfoLevel,