porting all github actions from bluesky-social/indigo to tangled CI

all: replace golang-lru v1 with v2

Using the same APIs, but now with generics.
The module already used v2, so this drops v1 as a direct requirement.

One of the cache fields is also unused.
For the sake of keeping this commit simple, just make a note of it.

Changed files
+21 -23
cmd
gosky
events
plc
+3 -4
cmd/gosky/main.go
··· 29 29 "golang.org/x/time/rate" 30 30 31 31 "github.com/gorilla/websocket" 32 - lru "github.com/hashicorp/golang-lru" 32 + lru "github.com/hashicorp/golang-lru/v2" 33 33 "github.com/ipfs/go-cid" 34 34 "github.com/ipfs/go-datastore" 35 35 blockstore "github.com/ipfs/go-ipfs-blockstore" ··· 188 188 hr := &api.ProdHandleResolver{} 189 189 resolveHandles := cctx.Bool("resolve-handles") 190 190 191 - cache, _ := lru.New(10000) 191 + cache, _ := lru.New[string, *cachedHandle](10000) 192 192 resolveDid := func(ctx context.Context, did string) (string, error) { 193 - val, ok := cache.Get(did) 193 + ch, ok := cache.Get(did) 194 194 if ok { 195 - ch := val.(*cachedHandle) 196 195 if time.Now().Before(ch.Valid) { 197 196 return ch.Handle, nil 198 197 }
+7 -7
events/dbpersist.go
··· 13 13 lexutil "github.com/bluesky-social/indigo/lex/util" 14 14 "github.com/bluesky-social/indigo/models" 15 15 "github.com/bluesky-social/indigo/util" 16 - lru "github.com/hashicorp/golang-lru" 16 + arc "github.com/hashicorp/golang-lru/arc/v2" 17 17 18 18 cid "github.com/ipfs/go-cid" 19 19 "gorm.io/gorm" ··· 61 61 batchOptions Options 62 62 lastFlush time.Time 63 63 64 - uidCache *lru.ARCCache 65 - didCache *lru.ARCCache 64 + uidCache *arc.ARCCache[models.Uid, string] 65 + didCache *arc.ARCCache[string, models.Uid] 66 66 } 67 67 68 68 type RepoEventRecord struct { ··· 91 91 options = DefaultOptions() 92 92 } 93 93 94 - uidCache, err := lru.NewARC(options.UIDCacheSize) 94 + uidCache, err := arc.NewARC[models.Uid, string](options.UIDCacheSize) 95 95 if err != nil { 96 96 return nil, fmt.Errorf("failed to create uid cache: %w", err) 97 97 } 98 98 99 - didCache, err := lru.NewARC(options.DIDCacheSize) 99 + didCache, err := arc.NewARC[string, models.Uid](options.DIDCacheSize) 100 100 if err != nil { 101 101 return nil, fmt.Errorf("failed to create did cache: %w", err) 102 102 } ··· 432 432 433 433 func (p *DbPersistence) uidForDid(ctx context.Context, did string) (models.Uid, error) { 434 434 if uid, ok := p.didCache.Get(did); ok { 435 - return uid.(models.Uid), nil 435 + return uid, nil 436 436 } 437 437 438 438 var u models.ActorInfo ··· 447 447 448 448 func (p *DbPersistence) didForUid(ctx context.Context, uid models.Uid) (string, error) { 449 449 if did, ok := p.uidCache.Get(uid); ok { 450 - return did.(string), nil 450 + return did, nil 451 451 } 452 452 453 453 var u models.ActorInfo
+6 -6
events/diskpersist.go
··· 15 15 16 16 "github.com/bluesky-social/indigo/api/atproto" 17 17 "github.com/bluesky-social/indigo/models" 18 - lru "github.com/hashicorp/golang-lru" 18 + arc "github.com/hashicorp/golang-lru/arc/v2" 19 19 "github.com/prometheus/client_golang/prometheus" 20 20 "github.com/prometheus/client_golang/prometheus/promauto" 21 21 cbg "github.com/whyrusleeping/cbor-gen" ··· 37 37 38 38 curSeq int64 39 39 40 - uidCache *lru.ARCCache 41 - didCache *lru.ARCCache 40 + uidCache *arc.ARCCache[models.Uid, string] // TODO: unused 41 + didCache *arc.ARCCache[string, models.Uid] 42 42 43 43 writers *sync.Pool 44 44 buffers *sync.Pool ··· 93 93 opts = DefaultDiskPersistOptions() 94 94 } 95 95 96 - uidCache, err := lru.NewARC(opts.UIDCacheSize) 96 + uidCache, err := arc.NewARC[models.Uid, string](opts.UIDCacheSize) 97 97 if err != nil { 98 98 return nil, fmt.Errorf("failed to create uid cache: %w", err) 99 99 } 100 100 101 - didCache, err := lru.NewARC(opts.DIDCacheSize) 101 + didCache, err := arc.NewARC[string, models.Uid](opts.DIDCacheSize) 102 102 if err != nil { 103 103 return nil, fmt.Errorf("failed to create did cache: %w", err) 104 104 } ··· 600 600 601 601 func (dp *DiskPersistence) uidForDid(ctx context.Context, did string) (models.Uid, error) { 602 602 if uid, ok := dp.didCache.Get(did); ok { 603 - return uid.(models.Uid), nil 603 + return uid, nil 604 604 } 605 605 606 606 var u models.ActorInfo
+1 -1
go.mod
··· 16 16 github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 17 17 github.com/gorilla/websocket v1.5.1 18 18 github.com/hashicorp/go-retryablehttp v0.7.5 19 - github.com/hashicorp/golang-lru v1.0.2 20 19 github.com/hashicorp/golang-lru/arc/v2 v2.0.6 21 20 github.com/hashicorp/golang-lru/v2 v2.0.7 22 21 github.com/icrowley/fake v0.0.0-20221112152111-d7b7e2276db2 ··· 82 81 83 82 require ( 84 83 github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect 84 + github.com/hashicorp/golang-lru v1.0.2 // indirect 85 85 github.com/jackc/puddle/v2 v2.2.1 // indirect 86 86 github.com/klauspost/compress v1.17.3 // indirect 87 87 github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
+4 -5
plc/caching.go
··· 5 5 "time" 6 6 7 7 "github.com/bluesky-social/indigo/did" 8 - lru "github.com/hashicorp/golang-lru" 8 + arc "github.com/hashicorp/golang-lru/arc/v2" 9 9 "go.opentelemetry.io/otel" 10 10 "go.opentelemetry.io/otel/attribute" 11 11 ) ··· 13 13 type CachingDidResolver struct { 14 14 res did.Resolver 15 15 maxAge time.Duration 16 - cache *lru.ARCCache 16 + cache *arc.ARCCache[string, *cachedDoc] 17 17 } 18 18 19 19 type cachedDoc struct { ··· 22 22 } 23 23 24 24 func NewCachingDidResolver(res did.Resolver, maxAge time.Duration, size int) *CachingDidResolver { 25 - c, err := lru.NewARC(size) 25 + c, err := arc.NewARC[string, *cachedDoc](size) 26 26 if err != nil { 27 27 panic(err) 28 28 } ··· 39 39 } 40 40 41 41 func (r *CachingDidResolver) tryCache(did string) (*did.Document, bool) { 42 - v, ok := r.cache.Get(did) 42 + cd, ok := r.cache.Get(did) 43 43 if !ok { 44 44 return nil, false 45 45 } 46 46 47 - cd := v.(*cachedDoc) 48 47 if time.Since(cd.cachedAt) > r.maxAge { 49 48 return nil, false 50 49 }