Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APIサーバーとDBサーバーを分割 #5

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions go/livestream_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion sql/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down