mirror of
https://tangled.org/evan.jarrett.net/at-container-registry
synced 2026-09-25 11:44:16 +00:00
need the actually new file
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package atproto
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/bluesky-social/indigo/atproto/identity"
|
||||
"github.com/earthboundkid/versioninfo/v2"
|
||||
)
|
||||
|
||||
var (
|
||||
// Shared identity directory instance (singleton)
|
||||
sharedDirectory identity.Directory
|
||||
directoryOnce sync.Once
|
||||
)
|
||||
|
||||
// GetDirectory returns a shared identity.Directory instance with an 8-hour cache TTL.
|
||||
// This is based on indigo's DefaultDirectory() but with a reduced cache TTL
|
||||
// to allow faster recovery from PDS migrations (8h instead of 24h).
|
||||
//
|
||||
// Using a shared instance ensures all identity lookups across the application
|
||||
// use the same cache, which is more memory-efficient and provides better cache hit rates.
|
||||
func GetDirectory() identity.Directory {
|
||||
directoryOnce.Do(func() {
|
||||
base := identity.BaseDirectory{
|
||||
PLCURL: identity.DefaultPLCURL,
|
||||
HTTPClient: http.Client{
|
||||
Timeout: time.Second * 10,
|
||||
Transport: &http.Transport{
|
||||
// would want this around 100ms for services doing lots of handle resolution. Impacts PLC connections as well, but not too bad.
|
||||
IdleConnTimeout: time.Millisecond * 1000,
|
||||
MaxIdleConns: 100,
|
||||
},
|
||||
},
|
||||
Resolver: net.Resolver{
|
||||
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
d := net.Dialer{Timeout: time.Second * 3}
|
||||
return d.DialContext(ctx, network, address)
|
||||
},
|
||||
},
|
||||
TryAuthoritativeDNS: true,
|
||||
// primary Bluesky PDS instance only supports HTTP resolution method
|
||||
SkipDNSDomainSuffixes: []string{".bsky.social"},
|
||||
UserAgent: "indigo-identity/" + versioninfo.Short(),
|
||||
}
|
||||
// Cache configuration:
|
||||
// - capacity: 250,000 entries
|
||||
// - hitTTL: 8 hours (reduced from indigo's default 24h for faster PDS migration recovery)
|
||||
// - errTTL: 2 minutes
|
||||
// - invalidHandleTTL: 5 minutes
|
||||
cached := identity.NewCacheDirectory(&base, 250_000, time.Hour*8, time.Minute*2, time.Minute*5)
|
||||
sharedDirectory = &cached
|
||||
})
|
||||
return sharedDirectory
|
||||
}
|
||||
Reference in New Issue
Block a user