Git Product home page Git Product logo

isucon13's People

Contributors

daaaai0809 avatar seiei-n avatar thirofoo avatar

Watchers

 avatar

isucon13's Issues

[Todo] : rank 算出 N+1

毎回全員分確認してるのは馬鹿な気がする。

var users []*UserModel
if err := tx.SelectContext(ctx, &users, "SELECT * FROM users"); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "failed to get users: "+err.Error())
}

[Todo] : livestream ranking も毎回全部取ってきてる ( stats )

cache して新しい livestream を ranking に追加していけば良さそう。
ただ、livestream の 削除がある場合はだるいのでやらなくてよさそう。

var livestreams []*LivestreamModel
if err := tx.SelectContext(ctx, &livestreams, "SELECT * FROM livestreams"); err != nil && !errors.Is(err, sql.ErrNoRows) {
return echo.NewHTTPError(http.StatusInternalServerError, "failed to get livestreams: "+err.Error())
}

[Todo] : livecomment N+1 ( stats ) ( 簡単に直せそう )

かなり簡単に直せそうな N+1。求めたいものがしょぼいからすぐ行けそう。

for _, livestream := range livestreams {
var livecomments []*LivecommentModel
if err := tx.SelectContext(ctx, &livecomments, "SELECT * FROM livecomments WHERE livestream_id = ?", livestream.ID); err != nil && !errors.Is(err, sql.ErrNoRows) {
return echo.NewHTTPError(http.StatusInternalServerError, "failed to get livecomments: "+err.Error())
}

[Todo] : searchLivstreams が N+1 2つあり

N+1 が 2つくらいあるかも。alp の 上から3番目 ( /api/livestream/search ) なので重要度高目。

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())
}
livestreamModels = append(livestreamModels, &ls)
}

livestreams := make([]Livestream, len(livestreamModels))
for i := range livestreamModels {
livestream, err := fillLivestreamResponse(ctx, tx, *livestreamModels[i])
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "failed to fill livestream: "+err.Error())
}
livestreams[i] = livestream
}

※ 2つ目は fillLivestreamsResponce に Select がある為 N+1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.