fork of indigo with slightly nicer lexgen

engine: remove wrapper counter and set methods (#529)

These were from earlier API design, and are just confusing now.

authored by bnewbold.net and committed by GitHub e82694c0 8aaa0545

+4 -2
automod/capture/capture_test.go
··· 1 1 package capture 2 2 3 3 import ( 4 + "context" 4 5 "testing" 5 6 6 7 "github.com/bluesky-social/indigo/automod/countstore" ··· 9 10 ) 10 11 11 12 func TestNoOpCaptureReplyRule(t *testing.T) { 13 + ctx := context.Background() 12 14 assert := assert.New(t) 13 15 14 16 eng := engine.EngineTestFixture() 15 17 capture := MustLoadCapture("testdata/capture_atprotocom.json") 16 18 assert.NoError(ProcessCaptureRules(&eng, capture)) 17 - c, err := eng.GetCount("automod-quota", "report", countstore.PeriodDay) 19 + c, err := eng.Counters.GetCount(ctx, "automod-quota", "report", countstore.PeriodDay) 18 20 assert.NoError(err) 19 21 assert.Equal(0, c) 20 - c, err = eng.GetCount("automod-quota", "takedown", countstore.PeriodDay) 22 + c, err = eng.Counters.GetCount(ctx, "automod-quota", "takedown", countstore.PeriodDay) 21 23 assert.NoError(err) 22 24 assert.Equal(0, c) 23 25 }
+1 -1
automod/engine/action_dedupe_test.go
··· 48 48 assert.NoError(eng.ProcessRecordOp(ctx, op)) 49 49 } 50 50 51 - reports, err := eng.GetCount("automod-quota", "report", countstore.PeriodDay) 51 + reports, err := eng.Counters.GetCount(ctx, "automod-quota", "report", countstore.PeriodDay) 52 52 assert.NoError(err) 53 53 assert.Equal(1, reports) 54 54 }
+4 -4
automod/engine/circuit_breaker_test.go
··· 57 57 assert.NoError(eng.ProcessRecordOp(ctx, op)) 58 58 } 59 59 60 - takedowns, err := eng.GetCount("automod-quota", "takedown", countstore.PeriodDay) 60 + takedowns, err := eng.Counters.GetCount(ctx, "automod-quota", "takedown", countstore.PeriodDay) 61 61 assert.NoError(err) 62 62 assert.Equal(QuotaModTakedownDay, takedowns) 63 63 64 - reports, err := eng.GetCount("automod-quota", "report", countstore.PeriodDay) 64 + reports, err := eng.Counters.GetCount(ctx, "automod-quota", "report", countstore.PeriodDay) 65 65 assert.NoError(err) 66 66 assert.Equal(0, reports) 67 67 } ··· 99 99 assert.NoError(eng.ProcessRecordOp(ctx, op)) 100 100 } 101 101 102 - takedowns, err := eng.GetCount("automod-quota", "takedown", countstore.PeriodDay) 102 + takedowns, err := eng.Counters.GetCount(ctx, "automod-quota", "takedown", countstore.PeriodDay) 103 103 assert.NoError(err) 104 104 assert.Equal(0, takedowns) 105 105 106 - reports, err := eng.GetCount("automod-quota", "report", countstore.PeriodDay) 106 + reports, err := eng.Counters.GetCount(ctx, "automod-quota", "report", countstore.PeriodDay) 107 107 assert.NoError(err) 108 108 assert.Equal(QuotaModReportDay, reports) 109 109 }
+7 -14
automod/engine/engine.go
··· 39 39 SlackWebhookURL string 40 40 } 41 41 42 + // Entrypoint for external code pushing arbitrary identity events in to the engine. 43 + // 44 + // This method can be called concurrently, though cached state may end up inconsistent if multiple events for the same account (DID) are processed in parallel. 42 45 func (eng *Engine) ProcessIdentityEvent(ctx context.Context, typ string, did syntax.DID) error { 43 46 // similar to an HTTP server, we want to recover any panics from rule execution 44 47 defer func() { ··· 76 79 return nil 77 80 } 78 81 82 + // Entrypoint for external code pushing repository updates. A simple repo commit results in multiple calls. 83 + // 84 + // This method can be called concurrently, though cached state may end up inconsistent if multiple events for the same account (DID) are processed in parallel. 79 85 func (eng *Engine) ProcessRecordOp(ctx context.Context, op RecordOp) error { 80 86 // similar to an HTTP server, we want to recover any panics from rule execution 81 87 defer func() { ··· 129 135 return nil 130 136 } 131 137 132 - func (e *Engine) GetCount(name, val, period string) (int, error) { 133 - return e.Counters.GetCount(context.TODO(), name, val, period) 134 - } 135 - 136 - func (e *Engine) GetCountDistinct(name, bucket, period string) (int, error) { 137 - return e.Counters.GetCountDistinct(context.TODO(), name, bucket, period) 138 - } 139 - 140 - // checks if `val` is an element of set `name` 141 - func (e *Engine) InSet(name, val string) (bool, error) { 142 - return e.Sets.InSet(context.TODO(), name, val) 143 - } 144 - 145 - // purge caches of any exiting metadata 138 + // Purge metadata caches for a specific account. 146 139 func (e *Engine) PurgeAccountCaches(ctx context.Context, did syntax.DID) error { 147 140 e.Directory.Purge(ctx, did.AtIdentifier()) 148 141 return e.Cache.Purge(ctx, "acct", did.String())
+3 -3
automod/engine/persisthelpers.go
··· 56 56 newReports := []ModReport{} 57 57 for _, r := range reports { 58 58 counterName := "automod-account-report-" + ReasonShortName(r.ReasonType) 59 - existing, err := eng.GetCount(counterName, did.String(), countstore.PeriodDay) 59 + existing, err := eng.Counters.GetCount(ctx, counterName, did.String(), countstore.PeriodDay) 60 60 if err != nil { 61 61 return nil, fmt.Errorf("checking report de-dupe counts: %w", err) 62 62 } ··· 77 77 if len(reports) == 0 { 78 78 return []ModReport{}, nil 79 79 } 80 - c, err := eng.GetCount("automod-quota", "report", countstore.PeriodDay) 80 + c, err := eng.Counters.GetCount(ctx, "automod-quota", "report", countstore.PeriodDay) 81 81 if err != nil { 82 82 return nil, fmt.Errorf("checking report action quota: %w", err) 83 83 } ··· 96 96 if !takedown { 97 97 return false, nil 98 98 } 99 - c, err := eng.GetCount("automod-quota", "takedown", countstore.PeriodDay) 99 + c, err := eng.Counters.GetCount(ctx, "automod-quota", "takedown", countstore.PeriodDay) 100 100 if err != nil { 101 101 return false, fmt.Errorf("checking takedown action quota: %w", err) 102 102 }