From e1ff6b2fa389e76c034d0939a2816af4239596b9 Mon Sep 17 00:00:00 2001 From: bryan newbold Date: Wed, 24 Jan 2024 23:01:05 -0800 Subject: [PATCH] effects: de-dupe labels, flags, etc at write-time --- automod/engine/effects.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/automod/engine/effects.go b/automod/engine/effects.go index bba1e166..2946ac48 100644 --- a/automod/engine/effects.go +++ b/automod/engine/effects.go @@ -86,6 +86,11 @@ func (e *Effects) IncrementDistinct(name, bucket, val string) { func (e *Effects) AddAccountLabel(val string) { e.mu.Lock() defer e.mu.Unlock() + for _, v := range e.AccountLabels { + if v == val { + return + } + } e.AccountLabels = append(e.AccountLabels, val) } @@ -93,6 +98,11 @@ func (e *Effects) AddAccountLabel(val string) { func (e *Effects) AddAccountFlag(val string) { e.mu.Lock() defer e.mu.Unlock() + for _, v := range e.AccountFlags { + if v == val { + return + } + } e.AccountFlags = append(e.AccountFlags, val) } @@ -104,6 +114,11 @@ func (e *Effects) ReportAccount(reason, comment string) { comment = "(reporting without comment)" } comment = "[automod] " + comment + for _, v := range e.AccountReports { + if v.ReasonType == reason { + return + } + } e.AccountReports = append(e.AccountReports, ModReport{ReasonType: reason, Comment: comment}) } @@ -116,6 +131,11 @@ func (e *Effects) TakedownAccount() { func (e *Effects) AddRecordLabel(val string) { e.mu.Lock() defer e.mu.Unlock() + for _, v := range e.RecordLabels { + if v == val { + return + } + } e.RecordLabels = append(e.RecordLabels, val) } @@ -123,6 +143,11 @@ func (e *Effects) AddRecordLabel(val string) { func (e *Effects) AddRecordFlag(val string) { e.mu.Lock() defer e.mu.Unlock() + for _, v := range e.RecordFlags { + if v == val { + return + } + } e.RecordFlags = append(e.RecordFlags, val) } @@ -135,6 +160,11 @@ func (e *Effects) ReportRecord(reason, comment string) { } else { comment = "[automod] " + comment } + for _, v := range e.RecordReports { + if v.ReasonType == reason { + return + } + } e.RecordReports = append(e.RecordReports, ModReport{ReasonType: reason, Comment: comment}) } @@ -147,6 +177,11 @@ func (e *Effects) TakedownRecord() { func (e *Effects) TakedownBlob(cid string) { e.mu.Lock() defer e.mu.Unlock() + for _, v := range e.BlobTakedowns { + if v == cid { + return + } + } e.BlobTakedowns = append(e.BlobTakedowns, cid) } -- 2.51.2