this repo has no description
0
fork

Configure Feed

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

remove three unnecessary direct dependencies (#505)

(see commit messages - please do not squash)

authored by

bnewbold and committed by
GitHub
bb08103f f36f09d2

+25 -30
+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
+2 -3
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 ··· 41 40 github.com/lestrrat-go/jwx/v2 v2.0.12 42 41 github.com/lib/pq v1.10.9 43 42 github.com/minio/sha256-simd v1.0.1 44 - github.com/mitchellh/go-homedir v1.1.0 45 43 github.com/mr-tron/base58 v1.2.0 46 44 github.com/multiformats/go-multihash v0.2.3 47 45 github.com/opensearch-project/opensearch-go/v2 v2.3.0 ··· 68 66 go.uber.org/automaxprocs v1.5.3 69 67 go.uber.org/zap v1.26.0 70 68 golang.org/x/crypto v0.15.0 71 - golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa 72 69 golang.org/x/sync v0.5.0 73 70 golang.org/x/text v0.14.0 74 71 golang.org/x/time v0.3.0 ··· 82 79 83 80 require ( 84 81 github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect 82 + github.com/hashicorp/golang-lru v1.0.2 // indirect 85 83 github.com/jackc/puddle/v2 v2.2.1 // indirect 86 84 github.com/klauspost/compress v1.17.3 // indirect 87 85 github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect ··· 90 88 github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect 91 89 github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect 92 90 github.com/whyrusleeping/cbor v0.0.0-20171005072247-63513f603b11 // indirect 91 + golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect 93 92 ) 94 93 95 94 require (
-2
go.sum
··· 449 449 github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= 450 450 github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM= 451 451 github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8= 452 - github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= 453 - github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= 454 452 github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 455 453 github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 456 454 github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
+1 -1
mst/mst_test.go
··· 5 5 "encoding/hex" 6 6 "fmt" 7 7 "io" 8 + "maps" 8 9 "math/rand" 9 10 "os" 10 11 "regexp" ··· 18 19 "github.com/ipld/go-car/v2" 19 20 "github.com/multiformats/go-multihash" 20 21 mh "github.com/multiformats/go-multihash" 21 - "golang.org/x/exp/maps" 22 22 ) 23 23 24 24 func randCid() cid.Cid {
+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 }
+2 -2
util/cliutil/util.go
··· 12 12 "github.com/bluesky-social/indigo/api" 13 13 "github.com/bluesky-social/indigo/did" 14 14 "github.com/bluesky-social/indigo/xrpc" 15 - homedir "github.com/mitchellh/go-homedir" 16 15 "github.com/urfave/cli/v2" 17 16 "gorm.io/driver/postgres" 18 17 "gorm.io/driver/sqlite" ··· 54 53 } 55 54 56 55 func readGoskyConfig() (*CliConfig, error) { 57 - d, err := homedir.Dir() 56 + // TODO: use os.UserConfigDir()/gosky, falling back to os.UserHomeDir()/.gosky for backwards compatibility. 57 + d, err := os.UserHomeDir() 58 58 if err != nil { 59 59 return nil, fmt.Errorf("cannot read Home directory") 60 60 }