this repo has no description
0
fork

Configure Feed

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

Add a separate TTL for negative handle caching so we don't keep inval… (#573)

…id handles for hours

authored by

Jaz and committed by
GitHub
f7eb4000 c72ce234

+15 -10
+10 -5
atproto/identity/cache_directory.go
··· 16 16 type CacheDirectory struct { 17 17 Inner Directory 18 18 ErrTTL time.Duration 19 + InvalidHandleTTL time.Duration 19 20 handleCache *expirable.LRU[syntax.Handle, HandleEntry] 20 21 identityCache *expirable.LRU[syntax.DID, IdentityEntry] 21 22 didLookupChans sync.Map ··· 67 68 var _ Directory = (*CacheDirectory)(nil) 68 69 69 70 // Capacity of zero means unlimited size. Similarly, ttl of zero means unlimited duration. 70 - func NewCacheDirectory(inner Directory, capacity int, hitTTL, errTTL time.Duration) CacheDirectory { 71 + func NewCacheDirectory(inner Directory, capacity int, hitTTL, errTTL time.Duration, invalidHandleTTL time.Duration) CacheDirectory { 71 72 return CacheDirectory{ 72 - ErrTTL: errTTL, 73 - Inner: inner, 74 - handleCache: expirable.NewLRU[syntax.Handle, HandleEntry](capacity, nil, hitTTL), 75 - identityCache: expirable.NewLRU[syntax.DID, IdentityEntry](capacity, nil, hitTTL), 73 + ErrTTL: errTTL, 74 + InvalidHandleTTL: invalidHandleTTL, 75 + Inner: inner, 76 + handleCache: expirable.NewLRU[syntax.Handle, HandleEntry](capacity, nil, hitTTL), 77 + identityCache: expirable.NewLRU[syntax.DID, IdentityEntry](capacity, nil, hitTTL), 76 78 } 77 79 } 78 80 ··· 85 87 86 88 func (d *CacheDirectory) IsIdentityStale(e *IdentityEntry) bool { 87 89 if e.Err != nil && time.Since(e.Updated) > d.ErrTTL { 90 + return true 91 + } 92 + if e.Identity != nil && e.Identity.Handle.IsInvalidHandle() && time.Since(e.Updated) > d.InvalidHandleTTL { 88 93 return true 89 94 } 90 95 return false
+1 -1
atproto/identity/identity.go
··· 76 76 // primary Bluesky PDS instance only supports HTTP resolution method 77 77 SkipDNSDomainSuffixes: []string{".bsky.social"}, 78 78 } 79 - cached := NewCacheDirectory(&base, 10000, time.Hour*24, time.Minute*2) 79 + cached := NewCacheDirectory(&base, 250_000, time.Hour*24, time.Minute*2, time.Minute*5) 80 80 return &cached 81 81 } 82 82
+2 -2
atproto/identity/live_test.go
··· 64 64 func TestCacheDirectory(t *testing.T) { 65 65 t.Skip("TODO: skipping live network test") 66 66 inner := BaseDirectory{} 67 - d := NewCacheDirectory(&inner, 1000, time.Hour*1, time.Hour*1) 67 + d := NewCacheDirectory(&inner, 1000, time.Hour*1, time.Hour*1, time.Hour*1) 68 68 for i := 0; i < 3; i = i + 1 { 69 69 testDirectoryLive(t, &d) 70 70 } ··· 87 87 TryAuthoritativeDNS: true, 88 88 SkipDNSDomainSuffixes: []string{".bsky.social"}, 89 89 } 90 - dir := NewCacheDirectory(&base, 1000, time.Hour*1, time.Hour*1) 90 + dir := NewCacheDirectory(&base, 1000, time.Hour*1, time.Hour*1, time.Hour*1) 91 91 // All 60 routines launch at the same time, so they should all miss the cache initially 92 92 routines := 60 93 93 wg := sync.WaitGroup{}
+1 -1
cmd/hepa/main.go
··· 157 157 } 158 158 dir = rdir 159 159 } else { 160 - cdir := identity.NewCacheDirectory(&baseDir, 1_500_000, time.Hour*24, time.Minute*2) 160 + cdir := identity.NewCacheDirectory(&baseDir, 1_500_000, time.Hour*24, time.Minute*2, time.Minute*5) 161 161 dir = &cdir 162 162 } 163 163 return dir, nil
+1 -1
cmd/palomar/main.go
··· 220 220 TryAuthoritativeDNS: true, 221 221 SkipDNSDomainSuffixes: []string{".bsky.social"}, 222 222 } 223 - dir := identity.NewCacheDirectory(&base, 1_500_000, time.Hour*24, time.Minute*2) 223 + dir := identity.NewCacheDirectory(&base, 1_500_000, time.Hour*24, time.Minute*2, time.Minute*5) 224 224 225 225 srv, err := search.NewServer( 226 226 db,