2026-02-24 11:29:17 +00:00
|
|
|
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
|
|
|
|
|
|
2026-02-24 11:48:58 +00:00
|
|
|
// Keep existing behavior: when over limit, reset dedupe map entirely.
|
2026-02-24 11:29:17 +00:00
|
|
|
if len(*processedMsgs) > maxEntries {
|
2026-02-24 11:48:58 +00:00
|
|
|
*processedMsgs = make(map[string]bool)
|
2026-02-24 11:29:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
}
|