Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cmyui committed Apr 21, 2024
1 parent ec5beee commit 3db1fc6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/v1/leaderboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func LeaderboardGET(md common.MethodData) common.CodeMessager {
return resp
}

var query = lbUserQuery + `WHERE user.id IN (?) AND user_stats.mode = ? ORDER BY user_stats.pp DESC, user_stats.ranked_score DESC`
var query = lbUserQuery + `WHERE users.id IN (?) AND user_stats.mode = ? ORDER BY user_stats.pp DESC, user_stats.ranked_score DESC`
query, params, _ := sqlx.In(query, results, modeInt+(rx*4))
rows, err := md.DB.Query(query, params...)
if err != nil {
Expand Down
30 changes: 20 additions & 10 deletions app/v1/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,16 +223,6 @@ func UserFullGET(md common.MethodData) common.CodeMessager {
return *shouldRet
}

// Hellest query I've ever done.
query := `
SELECT
user_stats.ranked_score, user_stats.total_score, user_stats.playcount, user_stats.playtime,
user_stats.replays_watched, user_stats.total_hits,
user_stats.avg_accuracy, user_stats.pp, user_stats.max_combo
FROM user_stats
LEFT JOIN users ON users.id = user_stats.user_id
WHERE ` + whereClause + ` AND ` + md.User.OnlyUserPublic(true) + ` AND user_stats.mode = ?
`
r := userFullResponse{}
var (
b singleBadge
Expand All @@ -249,6 +239,7 @@ WHERE ` + whereClause + ` AND ` + md.User.OnlyUserPublic(true) + ` AND user_stat
silence_end, notes, ban_datetime, email, clan_id
FROM users
WHERE `+whereClause+` AND `+md.User.OnlyUserPublic(true),
userIdParam,
).Scan(
&r.ID, &r.Username, &r.RegisteredOn, &r.Privileges, &r.LatestActivity,
&r.UsernameAKA, &r.Country, &r.PlayStyle, &r.FavouriteMode, &b.Icon,
Expand All @@ -264,6 +255,15 @@ WHERE ` + whereClause + ` AND ` + md.User.OnlyUserPublic(true) + ` AND user_stat
}

// Scan stats into response for all gamemodes, across vn/rx/ap
query := `
SELECT
user_stats.ranked_score, user_stats.total_score, user_stats.playcount, user_stats.playtime,
user_stats.replays_watched, user_stats.total_hits,
user_stats.avg_accuracy, user_stats.pp, user_stats.max_combo
FROM user_stats
LEFT JOIN users ON users.id = user_stats.user_id
WHERE ` + whereClause + ` AND ` + md.User.OnlyUserPublic(true) + ` AND user_stats.mode = ?
`
for _, relaxMode := range []int{0, 1, 2} {
modeOffset := relaxMode * 4
// Scan vanilla gamemode information into response
Expand All @@ -280,6 +280,11 @@ WHERE ` + whereClause + ` AND ` + md.User.OnlyUserPublic(true) + ` AND user_stat
return Err500
}

if relaxMode == 2 {
// AP only has osu! standard
continue
}

// Scan taiko gamemode information into response
err = md.DB.QueryRow(query, userIdParam, 1+modeOffset).Scan(
&r.Stats[relaxMode].Taiko.RankedScore, &r.Stats[relaxMode].Taiko.TotalScore, &r.Stats[relaxMode].Taiko.PlayCount, &r.Stats[relaxMode].Taiko.PlayTime,
Expand Down Expand Up @@ -308,6 +313,11 @@ WHERE ` + whereClause + ` AND ` + md.User.OnlyUserPublic(true) + ` AND user_stat
return Err500
}

if relaxMode == 1 {
// RX does not have mania
continue
}

// Scan mania gamemode information into response
err = md.DB.QueryRow(query, userIdParam, 3+modeOffset).Scan(
&r.Stats[relaxMode].Mania.RankedScore, &r.Stats[relaxMode].Mania.TotalScore, &r.Stats[relaxMode].Mania.PlayCount, &r.Stats[relaxMode].Mania.PlayTime,
Expand Down

0 comments on commit 3db1fc6

Please sign in to comment.