nandi/gleanpublic Fork 0
486c824
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.

Parallelize handle resolution using errgroupUnverified

Julien Robert committed 2026-04-23T22:28:18+02:00 Browse files
486c824 parent: 8ea190a
modified internal/server/annotations_handler.go +11 -3
@@ -10,6 +10,7 @@ import (
1010 "time"
1111
1212 "github.com/go-chi/chi/v5"
13+ "golang.org/x/sync/errgroup"
1314
1415 "pkg.rbrt.fr/glean/internal/atproto"
1516 "pkg.rbrt.fr/glean/internal/db"
@@ -169,9 +170,16 @@ func (s *Server) handleDeleteAnnotation(w http.ResponseWriter, r *http.Request)
169170 }
170171
171172 func resolveAnnotationHandles(ctx context.Context, annotations []*db.Annotation) {
173+ g, gCtx := errgroup.WithContext(ctx)
174+ g.SetLimit(5)
172175 for _, a := range annotations {
173- if a.AuthorDID != "" {
174- a.AuthorHandle = atproto.ResolveProfile(ctx, a.AuthorDID).Handle
175- }
176+ a := a
177+ g.Go(func() error {
178+ if a.AuthorDID != "" {
179+ a.AuthorHandle = atproto.ResolveProfile(gCtx, a.AuthorDID).Handle
180+ }
181+ return nil
182+ })
176183 }
184+ _ = g.Wait()
177185 }
@@ -10,6 +10,7 @@ import (
10 "time"10 "time"
11 11
12 "github.com/go-chi/chi/v5"12 "github.com/go-chi/chi/v5"
13+ "golang.org/x/sync/errgroup"
13 14
14 "pkg.rbrt.fr/glean/internal/atproto"15 "pkg.rbrt.fr/glean/internal/atproto"
15 "pkg.rbrt.fr/glean/internal/db"16 "pkg.rbrt.fr/glean/internal/db"
@@ -169,9 +170,16 @@ func (s *Server) handleDeleteAnnotation(w http.ResponseWriter, r *http.Request)
169 }170 }
170 171
171 func resolveAnnotationHandles(ctx context.Context, annotations []*db.Annotation) {172 func resolveAnnotationHandles(ctx context.Context, annotations []*db.Annotation) {
173+ g, gCtx := errgroup.WithContext(ctx)
174+ g.SetLimit(5)
172 for _, a := range annotations {175 for _, a := range annotations {
173- if a.AuthorDID != "" {176+ a := a
174- a.AuthorHandle = atproto.ResolveProfile(ctx, a.AuthorDID).Handle177+ g.Go(func() error {
175- }178+ if a.AuthorDID != "" {
179+ a.AuthorHandle = atproto.ResolveProfile(gCtx, a.AuthorDID).Handle
180+ }
181+ return nil
182+ })
176 }183 }
184+ _ = g.Wait()
177 }185 }
modified internal/server/dashboard_handler.go +14 -5
@@ -5,6 +5,8 @@ import (
55 "net/http"
66 "time"
77
8+ "golang.org/x/sync/errgroup"
9+
810 "pkg.rbrt.fr/glean/internal/atproto"
911 "pkg.rbrt.fr/glean/internal/cluster"
1012 )
@@ -115,10 +117,17 @@ func (s *Server) handleDismissArticleRecommendation(w http.ResponseWriter, r *ht
115117 }
116118
117119 func resolvePeopleHandles(ctx context.Context, people []*cluster.PersonRecommendation) {
120+ g, gCtx := errgroup.WithContext(ctx)
121+ g.SetLimit(5)
118122 for _, p := range people {
119- prof := atproto.ResolveProfile(ctx, p.DID)
120- p.Handle = prof.Handle
121- p.DisplayName = prof.DisplayName
122- p.AvatarURL = prof.AvatarURL
123- }
123+ p := p
124+ g.Go(func() error {
125+ prof := atproto.ResolveProfile(gCtx, p.DID)
126+ p.Handle = prof.Handle
127+ p.DisplayName = prof.DisplayName
128+ p.AvatarURL = prof.AvatarURL
129+ return nil
130+ })
131+ }
132+ _ = g.Wait()
124133 }
@@ -5,6 +5,8 @@ import (
5 "net/http"5 "net/http"
6 "time"6 "time"
7 7
8+ "golang.org/x/sync/errgroup"
9+
8 "pkg.rbrt.fr/glean/internal/atproto"10 "pkg.rbrt.fr/glean/internal/atproto"
9 "pkg.rbrt.fr/glean/internal/cluster"11 "pkg.rbrt.fr/glean/internal/cluster"
10 )12 )
@@ -115,10 +117,17 @@ func (s *Server) handleDismissArticleRecommendation(w http.ResponseWriter, r *ht
115 }117 }
116 118
117 func resolvePeopleHandles(ctx context.Context, people []*cluster.PersonRecommendation) {119 func resolvePeopleHandles(ctx context.Context, people []*cluster.PersonRecommendation) {
120+ g, gCtx := errgroup.WithContext(ctx)
121+ g.SetLimit(5)
118 for _, p := range people {122 for _, p := range people {
119- prof := atproto.ResolveProfile(ctx, p.DID)123+ p := p
120- p.Handle = prof.Handle124+ g.Go(func() error {
121- p.DisplayName = prof.DisplayName125+ prof := atproto.ResolveProfile(gCtx, p.DID)
122- p.AvatarURL = prof.AvatarURL126+ p.Handle = prof.Handle
123- }127+ p.DisplayName = prof.DisplayName
128+ p.AvatarURL = prof.AvatarURL
129+ return nil
130+ })
131+ }
132+ _ = g.Wait()
124 }133 }