modified internal/server/annotations_handler.go +11 -3
| @@ -10,6 +10,7 @@ import ( |
| 10 | 10 | "time" |
| 11 | 11 | |
| 12 | 12 | "github.com/go-chi/chi/v5" |
| 13 | + "golang.org/x/sync/errgroup" |
| 13 | 14 | |
| 14 | 15 | "pkg.rbrt.fr/glean/internal/atproto" |
| 15 | 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 | 172 | func resolveAnnotationHandles(ctx context.Context, annotations []*db.Annotation) { |
| 173 | + g, gCtx := errgroup.WithContext(ctx) |
| 174 | + g.SetLimit(5) |
| 172 | 175 | 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 | + }) |
| 176 | 183 | } |
| 184 | + _ = g.Wait() |
| 177 | 185 | } |
| @@ -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).Handle | 177 | + 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 ( |
| 5 | 5 | "net/http" |
| 6 | 6 | "time" |
| 7 | 7 | |
| 8 | + "golang.org/x/sync/errgroup" |
| 9 | + |
| 8 | 10 | "pkg.rbrt.fr/glean/internal/atproto" |
| 9 | 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 | 119 | func resolvePeopleHandles(ctx context.Context, people []*cluster.PersonRecommendation) { |
| 120 | + g, gCtx := errgroup.WithContext(ctx) |
| 121 | + g.SetLimit(5) |
| 118 | 122 | 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() |
| 124 | 133 | } |
| @@ -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.Handle | 124 | + g.Go(func() error { |
| 121 | - p.DisplayName = prof.DisplayName | 125 | + prof := atproto.ResolveProfile(gCtx, p.DID) |
| 122 | - p.AvatarURL = prof.AvatarURL | 126 | + 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 | } |