nandi/gleanpublic Fork 0
f973feb
Commits
Clone
git clone https://git.rickub.com/nandi/glean.git
git clone ssh://git@rickub.com/nandi/glean.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Add in-memory profile caching with TTLUnverified

Julien Robert committed 2026-04-23T22:29:11+02:00 Browse files
f973feb parent: 486c824
modified internal/atproto/auth.go +18 -0
@@ -6,6 +6,7 @@ import (
66 "net"
77 "net/http"
88 "os"
9+ "sync"
910 "time"
1011
1112 "github.com/bluesky-social/indigo/atproto/identity"
@@ -118,7 +119,23 @@ type Profile struct {
118119 AvatarURL string
119120 }
120121
122+type profileEntry struct {
123+ profile Profile
124+ fetched time.Time
125+}
126+
127+var profileCache sync.Map
128+
129+const profileCacheTTL = 4 * time.Hour
130+
121131 func ResolveProfile(ctx context.Context, did string) Profile {
132+ if cached, ok := profileCache.Load(did); ok {
133+ entry := cached.(*profileEntry)
134+ if time.Since(entry.fetched) < profileCacheTTL {
135+ return entry.profile
136+ }
137+ }
138+
122139 ident, err := ResolveIdentity(ctx, did)
123140 if err != nil {
124141 return Profile{}
@@ -140,5 +157,6 @@ func ResolveProfile(ctx context.Context, did string) Profile {
140157 p.DisplayName = dn
141158 p.AvatarURL = avatar
142159
160+ profileCache.Store(did, &profileEntry{profile: p, fetched: time.Now()})
143161 return p
144162 }
@@ -6,6 +6,7 @@ import (
6 "net"6 "net"
7 "net/http"7 "net/http"
8 "os"8 "os"
9+ "sync"
9 "time"10 "time"
10 11
11 "github.com/bluesky-social/indigo/atproto/identity"12 "github.com/bluesky-social/indigo/atproto/identity"
@@ -118,7 +119,23 @@ type Profile struct {
118 AvatarURL string119 AvatarURL string
119 }120 }
120 121
122+type profileEntry struct {
123+ profile Profile
124+ fetched time.Time
125+}
126+
127+var profileCache sync.Map
128+
129+const profileCacheTTL = 4 * time.Hour
130+
121 func ResolveProfile(ctx context.Context, did string) Profile {131 func ResolveProfile(ctx context.Context, did string) Profile {
132+ if cached, ok := profileCache.Load(did); ok {
133+ entry := cached.(*profileEntry)
134+ if time.Since(entry.fetched) < profileCacheTTL {
135+ return entry.profile
136+ }
137+ }
138+
122 ident, err := ResolveIdentity(ctx, did)139 ident, err := ResolveIdentity(ctx, did)
123 if err != nil {140 if err != nil {
124 return Profile{}141 return Profile{}
@@ -140,5 +157,6 @@ func ResolveProfile(ctx context.Context, did string) Profile {
140 p.DisplayName = dn157 p.DisplayName = dn
141 p.AvatarURL = avatar158 p.AvatarURL = avatar
142 159
160+ profileCache.Store(did, &profileEntry{profile: p, fetched: time.Now()})
143 return p161 return p
144 }162 }