A social RSS reader built on the AT Protocol. glean.at
glean atproto atmosphere rss feed social app
14
fork

Configure Feed

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

Parallelize handle resolution using errgroup

+24 -7
+11 -3
internal/server/annotations_handler.go
··· 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 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 }
+13 -4
internal/server/dashboard_handler.go
··· 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 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 + 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 + }) 123 131 } 132 + _ = g.Wait() 124 133 }