ax(node): rename receiver d to deduplicator on MessageDeduplicator
Single-letter receiver `d` violates AX Principle 1 (predictable names over short names). RFC-CORE-008 permits single-letter receivers only for `i` (range loops), `_` (discards), `t` (tests), and `c` (*core.Core). Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
parent
7664917fc2
commit
af7070f27a
1 changed files with 14 additions and 14 deletions
|
|
@ -74,28 +74,28 @@ func NewMessageDeduplicator(ttl time.Duration) *MessageDeduplicator {
|
|||
}
|
||||
|
||||
// if dedup.IsDuplicate(msg.ID) { continue } // drop already-processed message
|
||||
func (d *MessageDeduplicator) IsDuplicate(msgID string) bool {
|
||||
d.mutex.RLock()
|
||||
_, exists := d.seen[msgID]
|
||||
d.mutex.RUnlock()
|
||||
func (deduplicator *MessageDeduplicator) IsDuplicate(msgID string) bool {
|
||||
deduplicator.mutex.RLock()
|
||||
_, exists := deduplicator.seen[msgID]
|
||||
deduplicator.mutex.RUnlock()
|
||||
return exists
|
||||
}
|
||||
|
||||
// dedup.Mark(msg.ID) // call after IsDuplicate returns false
|
||||
func (d *MessageDeduplicator) Mark(msgID string) {
|
||||
d.mutex.Lock()
|
||||
d.seen[msgID] = time.Now()
|
||||
d.mutex.Unlock()
|
||||
func (deduplicator *MessageDeduplicator) Mark(msgID string) {
|
||||
deduplicator.mutex.Lock()
|
||||
deduplicator.seen[msgID] = time.Now()
|
||||
deduplicator.mutex.Unlock()
|
||||
}
|
||||
|
||||
// go dedup.Cleanup() // call periodically; entries older than ttl are dropped
|
||||
func (d *MessageDeduplicator) Cleanup() {
|
||||
d.mutex.Lock()
|
||||
defer d.mutex.Unlock()
|
||||
func (deduplicator *MessageDeduplicator) Cleanup() {
|
||||
deduplicator.mutex.Lock()
|
||||
defer deduplicator.mutex.Unlock()
|
||||
now := time.Now()
|
||||
for id, seen := range d.seen {
|
||||
if now.Sub(seen) > d.ttl {
|
||||
delete(d.seen, id)
|
||||
for id, seen := range deduplicator.seen {
|
||||
if now.Sub(seen) > deduplicator.ttl {
|
||||
delete(deduplicator.seen, id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue