this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

automod orga (#494)

Several more package extractions.

These are all the easy ones -- flagstore, cachestore, setstore,
directory -- all get yanked out in the same way as countstore already
was.

These didn't cause any major changes to package graph overall, it just
makes the main automod package smaller (yay). Near future targets are to
try to tug engines and events a bit further apart, and that might be
more complicated, so I thought I'd put up the easy-to-review diffs
first.

authored by

bnewbold and committed by
GitHub
f8867935 5d2ac2e4

+67 -44
+3 -2
automod/account_meta.go
··· 10 10 appbsky "github.com/bluesky-social/indigo/api/bsky" 11 11 "github.com/bluesky-social/indigo/atproto/identity" 12 12 "github.com/bluesky-social/indigo/atproto/syntax" 13 + "github.com/bluesky-social/indigo/automod/util" 13 14 ) 14 15 15 16 type ProfileSummary struct { ··· 95 96 Description: pv.Description, 96 97 DisplayName: pv.DisplayName, 97 98 }, 98 - AccountLabels: dedupeStrings(labels), 99 - AccountNegatedLabels: dedupeStrings(negLabels), 99 + AccountLabels: util.DedupeStrings(labels), 100 + AccountNegatedLabels: util.DedupeStrings(negLabels), 100 101 AccountFlags: flags, 101 102 } 102 103 if pv.PostsCount != nil {
+1 -7
automod/cachestore.go automod/cachestore/cachestore_mem.go
··· 1 - package automod 1 + package cachestore 2 2 3 3 import ( 4 4 "context" ··· 6 6 7 7 "github.com/hashicorp/golang-lru/v2/expirable" 8 8 ) 9 - 10 - type CacheStore interface { 11 - Get(ctx context.Context, name, key string) (string, error) 12 - Set(ctx context.Context, name, key string, val string) error 13 - Purge(ctx context.Context, name, key string) error 14 - } 15 9 16 10 type MemCacheStore struct { 17 11 Data *expirable.LRU[string, string]
+11
automod/cachestore/cachestore.go
··· 1 + package cachestore 2 + 3 + import ( 4 + "context" 5 + ) 6 + 7 + type CacheStore interface { 8 + Get(ctx context.Context, name, key string) (string, error) 9 + Set(ctx context.Context, name, key string, val string) error 10 + Purge(ctx context.Context, name, key string) error 11 + }
+6 -3
automod/engine.go
··· 8 8 9 9 "github.com/bluesky-social/indigo/atproto/identity" 10 10 "github.com/bluesky-social/indigo/atproto/syntax" 11 + "github.com/bluesky-social/indigo/automod/cachestore" 11 12 "github.com/bluesky-social/indigo/automod/countstore" 13 + "github.com/bluesky-social/indigo/automod/flagstore" 14 + "github.com/bluesky-social/indigo/automod/setstore" 12 15 "github.com/bluesky-social/indigo/xrpc" 13 16 ) 14 17 ··· 20 23 Directory identity.Directory 21 24 Rules RuleSet 22 25 Counters countstore.CountStore 23 - Sets SetStore 24 - Cache CacheStore 25 - Flags FlagStore 26 + Sets setstore.SetStore 27 + Cache cachestore.CacheStore 28 + Flags flagstore.FlagStore 26 29 RelayClient *xrpc.Client 27 30 BskyClient *xrpc.Client 28 31 // used to persist moderation actions in mod service (optional)
+5 -4
automod/event.go
··· 11 11 appbsky "github.com/bluesky-social/indigo/api/bsky" 12 12 "github.com/bluesky-social/indigo/atproto/syntax" 13 13 "github.com/bluesky-social/indigo/automod/countstore" 14 + "github.com/bluesky-social/indigo/automod/util" 14 15 "github.com/bluesky-social/indigo/xrpc" 15 16 ) 16 17 ··· 164 165 165 166 func dedupeLabelActions(labels, existing, existingNegated []string) []string { 166 167 newLabels := []string{} 167 - for _, val := range dedupeStrings(labels) { 168 + for _, val := range util.DedupeStrings(labels) { 168 169 exists := false 169 170 for _, e := range existingNegated { 170 171 if val == e { ··· 187 188 188 189 func dedupeFlagActions(flags, existing []string) []string { 189 190 newFlags := []string{} 190 - for _, val := range dedupeStrings(flags) { 191 + for _, val := range util.DedupeStrings(flags) { 191 192 exists := false 192 193 for _, e := range existing { 193 194 if val == e { ··· 483 484 func (e *RecordEvent) PersistRecordActions(ctx context.Context) error { 484 485 485 486 // NOTE: record-level actions are *not* currently de-duplicated (aka, the same record could be labeled multiple times, or re-reported, etc) 486 - newLabels := dedupeStrings(e.RecordLabels) 487 - newFlags := dedupeStrings(e.RecordFlags) 487 + newLabels := util.DedupeStrings(e.RecordLabels) 488 + newFlags := util.DedupeStrings(e.RecordFlags) 488 489 newReports := circuitBreakReports(&e.RepoEvent, e.RecordReports) 489 490 newTakedown := circuitBreakTakedown(&e.RepoEvent, e.RecordTakedown) 490 491 atURI := fmt.Sprintf("at://%s/%s/%s", e.Account.Identity.DID, e.Collection, e.RecordKey)
+4 -8
automod/flagstore.go automod/flagstore/flagstore_mem.go
··· 1 - package automod 1 + package flagstore 2 2 3 3 import ( 4 4 "context" 5 - ) 6 5 7 - type FlagStore interface { 8 - Get(ctx context.Context, key string) ([]string, error) 9 - Add(ctx context.Context, key string, flags []string) error 10 - Remove(ctx context.Context, key string, flags []string) error 11 - } 6 + "github.com/bluesky-social/indigo/automod/util" 7 + ) 12 8 13 9 type MemFlagStore struct { 14 10 Data map[string][]string ··· 36 32 for _, f := range flags { 37 33 v = append(v, f) 38 34 } 39 - v = dedupeStrings(v) 35 + v = util.DedupeStrings(v) 40 36 s.Data[key] = v 41 37 return nil 42 38 }
+11
automod/flagstore/flagstore.go
··· 1 + package flagstore 2 + 3 + import ( 4 + "context" 5 + ) 6 + 7 + type FlagStore interface { 8 + Get(ctx context.Context, key string) ([]string, error) 9 + Add(ctx context.Context, key string, flags []string) error 10 + Remove(ctx context.Context, key string, flags []string) error 11 + }
+1 -1
automod/flagstore_test.go automod/flagstore/flagstore_test.go
··· 1 - package automod 1 + package flagstore 2 2 3 3 import ( 4 4 "context"
+1 -1
automod/redis_cache.go automod/cachestore/cachestore_redis.go
··· 1 - package automod 1 + package cachestore 2 2 3 3 import ( 4 4 "context"
+1 -1
automod/redis_directory.go automod/directory/redis_directory.go
··· 1 - package automod 1 + package directory 2 2 3 3 import ( 4 4 "context"
+1 -1
automod/redis_flags.go automod/flagstore/flagstore_redis.go
··· 1 - package automod 1 + package flagstore 2 2 3 3 import ( 4 4 "context"
+1 -1
automod/redis_flagstore_test.go automod/flagstore/flagstore_redis_test.go
··· 1 - package automod 1 + package flagstore 2 2 3 3 import ( 4 4 "context"
+1 -1
automod/setstore.go automod/setstore/setstore.go
··· 1 - package automod 1 + package setstore 2 2 3 3 import ( 4 4 "context"
+6 -3
automod/testing.go
··· 11 11 appbsky "github.com/bluesky-social/indigo/api/bsky" 12 12 "github.com/bluesky-social/indigo/atproto/identity" 13 13 "github.com/bluesky-social/indigo/atproto/syntax" 14 + "github.com/bluesky-social/indigo/automod/cachestore" 14 15 "github.com/bluesky-social/indigo/automod/countstore" 16 + "github.com/bluesky-social/indigo/automod/flagstore" 17 + "github.com/bluesky-social/indigo/automod/setstore" 15 18 ) 16 19 17 20 func simpleRule(evt *RecordEvent, post *appbsky.FeedPost) error { ··· 41 44 simpleRule, 42 45 }, 43 46 } 44 - cache := NewMemCacheStore(10, time.Hour) 45 - flags := NewMemFlagStore() 46 - sets := NewMemSetStore() 47 + cache := cachestore.NewMemCacheStore(10, time.Hour) 48 + flags := flagstore.NewMemFlagStore() 49 + sets := setstore.NewMemSetStore() 47 50 sets.Sets["bad-hashtags"] = make(map[string]bool) 48 51 sets.Sets["bad-hashtags"]["slur"] = true 49 52 dir := identity.NewMockDirectory()
+2 -2
automod/util.go automod/util/strings.go
··· 1 - package automod 1 + package util 2 2 3 - func dedupeStrings(in []string) []string { 3 + func DedupeStrings(in []string) []string { 4 4 var out []string 5 5 seen := make(map[string]bool) 6 6 for _, v := range in {
+2 -2
cmd/hepa/main.go
··· 11 11 12 12 "github.com/bluesky-social/indigo/atproto/identity" 13 13 "github.com/bluesky-social/indigo/atproto/syntax" 14 - "github.com/bluesky-social/indigo/automod" 14 + "github.com/bluesky-social/indigo/automod/directory" 15 15 16 16 "github.com/carlmjohnson/versioninfo" 17 17 _ "github.com/joho/godotenv/autoload" ··· 116 116 } 117 117 var dir identity.Directory 118 118 if cctx.String("redis-url") != "" { 119 - rdir, err := automod.NewRedisDirectory(&baseDir, cctx.String("redis-url"), time.Hour*24, time.Minute*2) 119 + rdir, err := directory.NewRedisDirectory(&baseDir, cctx.String("redis-url"), time.Hour*24, time.Minute*2) 120 120 if err != nil { 121 121 return nil, err 122 122 }
+10 -7
cmd/hepa/server.go
··· 12 12 comatproto "github.com/bluesky-social/indigo/api/atproto" 13 13 "github.com/bluesky-social/indigo/atproto/identity" 14 14 "github.com/bluesky-social/indigo/automod" 15 + "github.com/bluesky-social/indigo/automod/cachestore" 15 16 "github.com/bluesky-social/indigo/automod/countstore" 17 + "github.com/bluesky-social/indigo/automod/flagstore" 16 18 "github.com/bluesky-social/indigo/automod/rules" 19 + "github.com/bluesky-social/indigo/automod/setstore" 17 20 "github.com/bluesky-social/indigo/util" 18 21 "github.com/bluesky-social/indigo/xrpc" 19 22 ··· 78 81 xrpcc.Auth.Handle = auth.Handle 79 82 } 80 83 81 - sets := automod.NewMemSetStore() 84 + sets := setstore.NewMemSetStore() 82 85 if config.SetsFileJSON != "" { 83 86 if err := sets.LoadFromFileJSON(config.SetsFileJSON); err != nil { 84 87 return nil, fmt.Errorf("initializing in-process setstore: %v", err) ··· 88 91 } 89 92 90 93 var counters countstore.CountStore 91 - var cache automod.CacheStore 92 - var flags automod.FlagStore 94 + var cache cachestore.CacheStore 95 + var flags flagstore.FlagStore 93 96 var rdb *redis.Client 94 97 if config.RedisURL != "" { 95 98 // generic client, for cursor state ··· 110 113 } 111 114 counters = cnt 112 115 113 - csh, err := automod.NewRedisCacheStore(config.RedisURL, 30*time.Minute) 116 + csh, err := cachestore.NewRedisCacheStore(config.RedisURL, 30*time.Minute) 114 117 if err != nil { 115 118 return nil, fmt.Errorf("initializing redis cachestore: %v", err) 116 119 } 117 120 cache = csh 118 121 119 - flg, err := automod.NewRedisFlagStore(config.RedisURL) 122 + flg, err := flagstore.NewRedisFlagStore(config.RedisURL) 120 123 if err != nil { 121 124 return nil, fmt.Errorf("initializing redis flagstore: %v", err) 122 125 } 123 126 flags = flg 124 127 } else { 125 128 counters = countstore.NewMemCountStore() 126 - cache = automod.NewMemCacheStore(5_000, 30*time.Minute) 127 - flags = automod.NewMemFlagStore() 129 + cache = cachestore.NewMemCacheStore(5_000, 30*time.Minute) 130 + flags = flagstore.NewMemFlagStore() 128 131 } 129 132 130 133 engine := automod.Engine{