Skip to content

Commit

Permalink
Merge pull request #9 from chibiegg/math/3
Browse files Browse the repository at this point in the history
add indexes
  • Loading branch information
chibiegg committed Oct 20, 2018
2 parents a512f56 + 393e5eb commit bf84ee5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions webapp/go/src/isucon8/isucoin/controller/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (h *Handler) Info(w http.ResponseWriter, r *http.Request, _ httprouter.Para
if lt.After(bySecTime) {
bySecTime = time.Date(lt.Year(), lt.Month(), lt.Day(), lt.Hour(), lt.Minute(), lt.Second(), 0, lt.Location())
}
res["chart_by_sec"], err = model.GetCandlestickData(h.db, bySecTime, "%Y-%m-%d %H:%i:%s")
res["chart_by_sec"], err = model.GetCandlestickData(h.db, bySecTime, "created_at_sec")
if err != nil {
h.handleError(w, errors.Wrap(err, "model.GetCandlestickData by sec"), 500)
return
Expand All @@ -184,7 +184,7 @@ func (h *Handler) Info(w http.ResponseWriter, r *http.Request, _ httprouter.Para
if lt.After(byMinTime) {
byMinTime = time.Date(lt.Year(), lt.Month(), lt.Day(), lt.Hour(), lt.Minute(), 0, 0, lt.Location())
}
res["chart_by_min"], err = model.GetCandlestickData(h.db, byMinTime, "%Y-%m-%d %H:%i:00")
res["chart_by_min"], err = model.GetCandlestickData(h.db, byMinTime, "created_at_min")
if err != nil {
h.handleError(w, errors.Wrap(err, "model.GetCandlestickData by min"), 500)
return
Expand All @@ -194,7 +194,7 @@ func (h *Handler) Info(w http.ResponseWriter, r *http.Request, _ httprouter.Para
if lt.After(byHourTime) {
byHourTime = time.Date(lt.Year(), lt.Month(), lt.Day(), lt.Hour(), 0, 0, 0, lt.Location())
}
res["chart_by_hour"], err = model.GetCandlestickData(h.db, byHourTime, "%Y-%m-%d %H:00:00")
res["chart_by_hour"], err = model.GetCandlestickData(h.db, byHourTime, "created_at_hou")
if err != nil {
h.handleError(w, errors.Wrap(err, "model.GetCandlestickData by hour"), 500)
return
Expand Down
6 changes: 3 additions & 3 deletions webapp/go/src/isucon8/isucoin/model/trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ func GetLatestTrade(d QueryExecutor) (*Trade, error) {
return scanTrade(d.Query("SELECT * FROM trade ORDER BY id DESC LIMIT 1"))
}

func GetCandlestickData(d QueryExecutor, mt time.Time, tf string) ([]*CandlestickData, error) {
func GetCandlestickData(d QueryExecutor, mt time.Time, timeColumnName string) ([]*CandlestickData, error) {
query := fmt.Sprintf(`
SELECT m.t, a.price, b.price, m.h, m.l
FROM (
SELECT
STR_TO_DATE(DATE_FORMAT(created_at, '%s'), '%s') AS t,
%s AS t,
MIN(id) AS min_id,
MAX(id) AS max_id,
MAX(price) AS h,
Expand All @@ -55,7 +55,7 @@ func GetCandlestickData(d QueryExecutor, mt time.Time, tf string) ([]*Candlestic
JOIN trade a ON a.id = m.min_id
JOIN trade b ON b.id = m.max_id
ORDER BY m.t
`, tf, "%Y-%m-%d %H:%i:%s")
`, timeColumnName)
return scanCandlestickDatas(d.Query(query, mt))
}

Expand Down
2 changes: 1 addition & 1 deletion webapp/go/src/isucon8/isucoin/webapp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func main() {
var (
port = getEnv("APP_PORT", "5000")
dbhost = getEnv("DB_HOST", "127.0.0.1")
dbport = getEnv("DB_PORT", "3306")
dbport = getEnv("DB_PORT", "13306")
dbuser = getEnv("DB_USER", "root")
dbpass = getEnv("DB_PASSWORD", "")
dbname = getEnv("DB_NAME", "isucoin")
Expand Down

0 comments on commit bf84ee5

Please sign in to comment.