picoclaw/pkg/channels/wecom/dedupe.go
esubaalew db17cdc86d test(wecom): align dedupe rotation behavior and add helper tests
Match rotation semantics to prior behavior by fully resetting the dedupe map
once the size limit is exceeded, and add focused tests for duplicate detection
and boundary rotation behavior.
2026-03-02 18:50:29 +03:00

28 lines
704 B
Go

package wecom
import "sync"
const wecomMaxProcessedMessages = 1000
// markMessageProcessed marks msgID as processed and returns false for duplicates.
// All map reads/writes (including len) are protected by msgMu to avoid races.
func markMessageProcessed(msgMu *sync.RWMutex, processedMsgs *map[string]bool, msgID string, maxEntries int) bool {
if maxEntries <= 0 {
maxEntries = wecomMaxProcessedMessages
}
msgMu.Lock()
defer msgMu.Unlock()
if (*processedMsgs)[msgID] {
return false
}
(*processedMsgs)[msgID] = true
// Keep existing behavior: when over limit, reset dedupe map entirely.
if len(*processedMsgs) > maxEntries {
*processedMsgs = make(map[string]bool)
}
return true
}