diff --git a/go/livestream_handler.go b/go/livestream_handler.go index 4716dc5..643d087 100644 --- a/go/livestream_handler.go +++ b/go/livestream_handler.go @@ -197,14 +197,24 @@ func searchLivestreamsHandler(c echo.Context) error { return echo.NewHTTPError(http.StatusInternalServerError, "failed to get keyTaggedLivestreams: "+err.Error()) } + var livestreamIDs []int for _, keyTaggedLivestream := range keyTaggedLivestreams { - ls := LivestreamModel{} - if err := tx.GetContext(ctx, &ls, "SELECT * FROM livestreams WHERE id = ?", keyTaggedLivestream.LivestreamID); err != nil { - return echo.NewHTTPError(http.StatusInternalServerError, "failed to get livestreams: "+err.Error()) + livestreamIDs = append(livestreamIDs, int(keyTaggedLivestream.LivestreamID)) + } + + var livestreamModels []*LivestreamModel + if len(livestreamIDs) > 0 { + query, params, err := sqlx.In("SELECT * FROM livestreams WHERE id IN (?)", livestreamIDs) + if err != nil { + return echo.NewHTTPError(http.StatusInternalServerError, "failed to construct IN query: "+err.Error()) } - livestreamModels = append(livestreamModels, &ls) + query = tx.Rebind(query) + if err := tx.SelectContext(ctx, &livestreamModels, query, params...); err != nil { + return echo.NewHTTPError(http.StatusInternalServerError, "failed to get livestreamModels: "+err.Error()) + } } + } else { // 検索条件なし query := `SELECT * FROM livestreams ORDER BY id DESC` diff --git a/go/main.go b/go/main.go index 0c9e27c..cf32880 100644 --- a/go/main.go +++ b/go/main.go @@ -60,7 +60,7 @@ func connectDB(logger echo.Logger) (*sqlx.DB, error) { // 環境変数がセットされていなかった場合でも一旦動かせるように、デフォルト値を入れておく // この挙動を変更して、エラーを出すようにしてもいいかもしれない conf.Net = "tcp" - conf.Addr = net.JoinHostPort("127.0.0.1", "3306") + conf.Addr = net.JoinHostPort("13.113.12.49", "3306") conf.User = "isucon" conf.Passwd = "isucon" conf.DBName = "isupipe" diff --git a/sql/init.sh b/sql/init.sh index caced85..06e942f 100755 --- a/sql/init.sh +++ b/sql/init.sh @@ -7,7 +7,7 @@ if test -f /home/isucon/env.sh; then . /home/isucon/env.sh fi -ISUCON_DB_HOST=${ISUCON13_MYSQL_DIALCONFIG_ADDRESS:-127.0.0.1} +ISUCON_DB_HOST=${ISUCON13_MYSQL_DIALCONFIG_ADDRESS:-13.113.12.49} ISUCON_DB_PORT=${ISUCON13_MYSQL_DIALCONFIG_PORT:-3306} ISUCON_DB_USER=${ISUCON13_MYSQL_DIALCONFIG_USER:-isucon} ISUCON_DB_PASSWORD=${ISUCON13_MYSQL_DIALCONFIG_PASSWORD:-isucon}