Skip to content

Commit

Permalink
getReactionsHandlerを並列化
Browse files Browse the repository at this point in the history
  • Loading branch information
pikachu0310 committed Nov 25, 2023
1 parent 152f948 commit 69f7151
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions webapp/go/reaction_handler.go
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"golang.org/x/sync/errgroup"
"net/http"
"strconv"
"time"
Expand Down Expand Up @@ -67,13 +68,21 @@ func getReactionsHandler(c echo.Context) error {
}

reactions := make([]Reaction, len(reactionModels))
var eg errgroup.Group
for i := range reactionModels {
reaction, err := fillReactionResponse(ctx, tx, reactionModels[i])
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "failed to fill reaction: "+err.Error())
}
eg.Go(func() error {
reaction, err := fillReactionResponse(ctx, tx, reactionModels[i])
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "failed to fill reaction: "+err.Error())
}

reactions[i] = reaction
reactions[i] = reaction
return nil
})
}
err = eg.Wait()
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "failed to fill reaction: "+err.Error())
}

if err := tx.Commit(); err != nil {
Expand Down

0 comments on commit 69f7151

Please sign in to comment.