Skip to content

Commit

Permalink
automod: quick fix to remove duplicate implementation of countstore. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
warpfork authored Dec 22, 2023
2 parents 4ee9720 + e2eeced commit 5d2ac2e
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 112 deletions.
3 changes: 2 additions & 1 deletion automod/action_dedupe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
appbsky "github.com/bluesky-social/indigo/api/bsky"
"github.com/bluesky-social/indigo/atproto/identity"
"github.com/bluesky-social/indigo/atproto/syntax"
"github.com/bluesky-social/indigo/automod/countstore"

"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -39,7 +40,7 @@ func TestAccountReportDedupe(t *testing.T) {
assert.NoError(engine.ProcessRecord(ctx, id1.DID, path, cid1, &p1))
}

reports, err := engine.GetCount("automod-quota", "report", PeriodDay)
reports, err := engine.GetCount("automod-quota", "report", countstore.PeriodDay)
assert.NoError(err)
assert.Equal(1, reports)
}
5 changes: 3 additions & 2 deletions automod/capture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package automod
import (
"testing"

"github.com/bluesky-social/indigo/automod/countstore"
"github.com/stretchr/testify/assert"
)

Expand All @@ -12,10 +13,10 @@ func TestNoOpCaptureReplyRule(t *testing.T) {
engine := EngineTestFixture()
capture := MustLoadCapture("testdata/capture_atprotocom.json")
assert.NoError(ProcessCaptureRules(&engine, capture))
c, err := engine.GetCount("automod-quota", "report", PeriodDay)
c, err := engine.GetCount("automod-quota", "report", countstore.PeriodDay)
assert.NoError(err)
assert.Equal(0, c)
c, err = engine.GetCount("automod-quota", "takedown", PeriodDay)
c, err = engine.GetCount("automod-quota", "takedown", countstore.PeriodDay)
assert.NoError(err)
assert.Equal(0, c)
}
9 changes: 5 additions & 4 deletions automod/circuit_breaker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
appbsky "github.com/bluesky-social/indigo/api/bsky"
"github.com/bluesky-social/indigo/atproto/identity"
"github.com/bluesky-social/indigo/atproto/syntax"
"github.com/bluesky-social/indigo/automod/countstore"

"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -49,11 +50,11 @@ func TestTakedownCircuitBreaker(t *testing.T) {
assert.NoError(engine.ProcessRecord(ctx, ident.DID, path, cid1, &p1))
}

takedowns, err := engine.GetCount("automod-quota", "takedown", PeriodDay)
takedowns, err := engine.GetCount("automod-quota", "takedown", countstore.PeriodDay)
assert.NoError(err)
assert.Equal(QuotaModTakedownDay, takedowns)

reports, err := engine.GetCount("automod-quota", "report", PeriodDay)
reports, err := engine.GetCount("automod-quota", "report", countstore.PeriodDay)
assert.NoError(err)
assert.Equal(0, reports)
}
Expand Down Expand Up @@ -84,11 +85,11 @@ func TestReportCircuitBreaker(t *testing.T) {
assert.NoError(engine.ProcessRecord(ctx, ident.DID, path, cid1, &p1))
}

takedowns, err := engine.GetCount("automod-quota", "takedown", PeriodDay)
takedowns, err := engine.GetCount("automod-quota", "takedown", countstore.PeriodDay)
assert.NoError(err)
assert.Equal(0, takedowns)

reports, err := engine.GetCount("automod-quota", "report", PeriodDay)
reports, err := engine.GetCount("automod-quota", "report", countstore.PeriodDay)
assert.NoError(err)
assert.Equal(QuotaModReportDay, reports)
}
99 changes: 0 additions & 99 deletions automod/countstore.go

This file was deleted.

7 changes: 4 additions & 3 deletions automod/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
comatproto "github.com/bluesky-social/indigo/api/atproto"
appbsky "github.com/bluesky-social/indigo/api/bsky"
"github.com/bluesky-social/indigo/atproto/syntax"
"github.com/bluesky-social/indigo/automod/countstore"
"github.com/bluesky-social/indigo/xrpc"
)

Expand Down Expand Up @@ -205,7 +206,7 @@ func dedupeReportActions(evt *RepoEvent, reports []ModReport) []ModReport {
newReports := []ModReport{}
for _, r := range reports {
counterName := "automod-account-report-" + reasonShortName(r.ReasonType)
existing := evt.GetCount(counterName, evt.Account.Identity.DID.String(), PeriodDay)
existing := evt.GetCount(counterName, evt.Account.Identity.DID.String(), countstore.PeriodDay)
if existing > 0 {
evt.Logger.Debug("skipping account report due to counter", "existing", existing, "reason", reasonShortName(r.ReasonType))
} else {
Expand All @@ -220,7 +221,7 @@ func circuitBreakReports(evt *RepoEvent, reports []ModReport) []ModReport {
if len(reports) == 0 {
return []ModReport{}
}
if evt.GetCount("automod-quota", "report", PeriodDay) >= QuotaModReportDay {
if evt.GetCount("automod-quota", "report", countstore.PeriodDay) >= QuotaModReportDay {
evt.Logger.Warn("CIRCUIT BREAKER: automod reports")
return []ModReport{}
}
Expand All @@ -232,7 +233,7 @@ func circuitBreakTakedown(evt *RepoEvent, takedown bool) bool {
if !takedown {
return takedown
}
if evt.GetCount("automod-quota", "takedown", PeriodDay) >= QuotaModTakedownDay {
if evt.GetCount("automod-quota", "takedown", countstore.PeriodDay) >= QuotaModTakedownDay {
evt.Logger.Warn("CIRCUIT BREAKER: automod takedowns")
return false
}
Expand Down
3 changes: 2 additions & 1 deletion automod/rules/mentions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rules
import (
appbsky "github.com/bluesky-social/indigo/api/bsky"
"github.com/bluesky-social/indigo/automod"
"github.com/bluesky-social/indigo/automod/countstore"
)

var _ automod.PostRuleFunc = DistinctMentionsRule
Expand Down Expand Up @@ -30,7 +31,7 @@ func DistinctMentionsRule(evt *automod.RecordEvent, post *appbsky.FeedPost) erro
if !newMentions {
return nil
}
if mentionHourlyThreshold <= evt.GetCountDistinct("mentions", did, automod.PeriodHour) {
if mentionHourlyThreshold <= evt.GetCountDistinct("mentions", did, countstore.PeriodHour) {
evt.AddAccountFlag("high-distinct-mentions")
}

Expand Down
2 changes: 1 addition & 1 deletion automod/rules/replies.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func IdenticalReplyPostRule(evt *automod.RecordEvent, post *appbsky.FeedPost) er
}

// increment first. use a specific period (IncrementPeriod()) to reduce the number of counters (one per unique post text)
period := automod.PeriodDay
period := countstore.PeriodDay
bucket := evt.Account.Identity.DID.String() + "/" + HashOfString(post.Text)
evt.IncrementPeriod("reply-text", bucket, period)

Expand Down
3 changes: 2 additions & 1 deletion automod/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
appbsky "github.com/bluesky-social/indigo/api/bsky"
"github.com/bluesky-social/indigo/atproto/identity"
"github.com/bluesky-social/indigo/atproto/syntax"
"github.com/bluesky-social/indigo/automod/countstore"
)

func simpleRule(evt *RecordEvent, post *appbsky.FeedPost) error {
Expand Down Expand Up @@ -54,7 +55,7 @@ func EngineTestFixture() Engine {
engine := Engine{
Logger: slog.Default(),
Directory: &dir,
Counters: NewMemCountStore(),
Counters: countstore.NewMemCountStore(),
Sets: sets,
Flags: flags,
Cache: cache,
Expand Down

0 comments on commit 5d2ac2e

Please sign in to comment.