fork of indigo with slightly nicer lexgen

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