Skip to content

Commit

Permalink
automod: quick extraction of cachestore package.
Browse files Browse the repository at this point in the history
Did not rename, so some names are stuttery (cachestore.CacheStore).
This can be fixed in a future pass if desired; today's goal is just
more packages and getting the filesystem tree approximately right.
  • Loading branch information
warpfork committed Dec 22, 2023
1 parent be984df commit 9923ee1
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 13 deletions.
11 changes: 11 additions & 0 deletions automod/cachestore/cachestore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package cachestore

import (
"context"
)

type CacheStore interface {
Get(ctx context.Context, name, key string) (string, error)
Set(ctx context.Context, name, key string, val string) error
Purge(ctx context.Context, name, key string) error
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package automod
package cachestore

import (
"context"
Expand All @@ -7,12 +7,6 @@ import (
"github.com/hashicorp/golang-lru/v2/expirable"
)

type CacheStore interface {
Get(ctx context.Context, name, key string) (string, error)
Set(ctx context.Context, name, key string, val string) error
Purge(ctx context.Context, name, key string) error
}

type MemCacheStore struct {
Data *expirable.LRU[string, string]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package automod
package cachestore

import (
"context"
Expand Down
3 changes: 2 additions & 1 deletion automod/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/bluesky-social/indigo/atproto/identity"
"github.com/bluesky-social/indigo/atproto/syntax"
"github.com/bluesky-social/indigo/automod/cachestore"
"github.com/bluesky-social/indigo/automod/countstore"
"github.com/bluesky-social/indigo/automod/flagstore"
"github.com/bluesky-social/indigo/xrpc"
Expand All @@ -22,7 +23,7 @@ type Engine struct {
Rules RuleSet
Counters countstore.CountStore
Sets SetStore
Cache CacheStore
Cache cachestore.CacheStore
Flags flagstore.FlagStore
RelayClient *xrpc.Client
BskyClient *xrpc.Client
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/cachestore"
"github.com/bluesky-social/indigo/automod/countstore"
"github.com/bluesky-social/indigo/automod/flagstore"
)
Expand Down Expand Up @@ -42,7 +43,7 @@ func EngineTestFixture() Engine {
simpleRule,
},
}
cache := NewMemCacheStore(10, time.Hour)
cache := cachestore.NewMemCacheStore(10, time.Hour)
flags := flagstore.NewMemFlagStore()
sets := NewMemSetStore()
sets.Sets["bad-hashtags"] = make(map[string]bool)
Expand Down
7 changes: 4 additions & 3 deletions cmd/hepa/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
comatproto "github.com/bluesky-social/indigo/api/atproto"
"github.com/bluesky-social/indigo/atproto/identity"
"github.com/bluesky-social/indigo/automod"
"github.com/bluesky-social/indigo/automod/cachestore"
"github.com/bluesky-social/indigo/automod/countstore"
"github.com/bluesky-social/indigo/automod/flagstore"
"github.com/bluesky-social/indigo/automod/rules"
Expand Down Expand Up @@ -89,7 +90,7 @@ func NewServer(dir identity.Directory, config Config) (*Server, error) {
}

var counters countstore.CountStore
var cache automod.CacheStore
var cache cachestore.CacheStore
var flags flagstore.FlagStore
var rdb *redis.Client
if config.RedisURL != "" {
Expand All @@ -111,7 +112,7 @@ func NewServer(dir identity.Directory, config Config) (*Server, error) {
}
counters = cnt

csh, err := automod.NewRedisCacheStore(config.RedisURL, 30*time.Minute)
csh, err := cachestore.NewRedisCacheStore(config.RedisURL, 30*time.Minute)
if err != nil {
return nil, fmt.Errorf("initializing redis cachestore: %v", err)
}
Expand All @@ -124,7 +125,7 @@ func NewServer(dir identity.Directory, config Config) (*Server, error) {
flags = flg
} else {
counters = countstore.NewMemCountStore()
cache = automod.NewMemCacheStore(5_000, 30*time.Minute)
cache = cachestore.NewMemCacheStore(5_000, 30*time.Minute)
flags = flagstore.NewMemFlagStore()
}

Expand Down

0 comments on commit 9923ee1

Please sign in to comment.