Files
cc-connect/core/dedup.go
T
chenhg5andClaude e8e39413e8 refactor(session): add context-aware event sending and secure arg logging
Add context-aware select statements when sending events to prevent blocking on closed channels. Implement secure argument logging using RedactArgs to mask sensitive flags. Add atomic file writes and locks for config safety. Improve session handling with mutex protection and deduplication checks.

generated by llmgit

Co-Authored-By: Claude <noreply@anthropic.com>
2026-03-04 12:38:37 +08:00

40 lines
764 B
Go

package core
import (
"sync"
"time"
)
const dedupTTL = 60 * time.Second
// MessageDedup tracks recently seen message IDs to prevent duplicate processing.
// Safe for concurrent use.
type MessageDedup struct {
mu sync.Mutex
seen map[string]time.Time
}
// IsDuplicate returns true if msgID was already seen within the TTL window.
// Empty msgID is never considered a duplicate.
func (d *MessageDedup) IsDuplicate(msgID string) bool {
if msgID == "" {
return false
}
d.mu.Lock()
defer d.mu.Unlock()
if d.seen == nil {
d.seen = make(map[string]time.Time)
}
now := time.Now()
for k, t := range d.seen {
if now.Sub(t) > dedupTTL {
delete(d.seen, k)
}
}
if _, ok := d.seen[msgID]; ok {
return true
}
d.seen[msgID] = now
return false
}