make Global- and CountryLeaderboardRank nullable
This commit is contained in:
parent
622658f5aa
commit
cc90105130
|
@ -92,21 +92,30 @@ func LeaderboardGET(md common.MethodData) common.CodeMessager {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
u.ChosenMode.Level = ocl.GetLevelPrecise(int64(u.ChosenMode.TotalScore))
|
u.ChosenMode.Level = ocl.GetLevelPrecise(int64(u.ChosenMode.TotalScore))
|
||||||
if i := leaderboardPosition(md.R, m, u.ID); i != 0 {
|
if i := leaderboardPosition(md.R, m, u.ID); i != nil {
|
||||||
u.ChosenMode.GlobalLeaderboardRank = &i
|
u.ChosenMode.GlobalLeaderboardRank = i
|
||||||
}
|
}
|
||||||
if i := countryPosition(md.R, m, u.ID, u.Country); i != 0 {
|
if i := countryPosition(md.R, m, u.ID, u.Country); i != nil {
|
||||||
u.ChosenMode.CountryLeaderboardRank = &i
|
u.ChosenMode.CountryLeaderboardRank = i
|
||||||
}
|
}
|
||||||
resp.Users = append(resp.Users, u)
|
resp.Users = append(resp.Users, u)
|
||||||
}
|
}
|
||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
|
||||||
func leaderboardPosition(r *redis.Client, mode string, user int) int {
|
func leaderboardPosition(r *redis.Client, mode string, user int) *int {
|
||||||
return int(r.ZRevRank("ripple:leaderboard:"+mode, strconv.Itoa(user)).Val()) + 1
|
return _position(r, "ripple:leaderboard:"+mode, user)
|
||||||
}
|
}
|
||||||
|
|
||||||
func countryPosition(r *redis.Client, mode string, user int, country string) int {
|
func countryPosition(r *redis.Client, mode string, user int, country string) *int {
|
||||||
return int(r.ZRevRank("ripple:leaderboard:"+mode+":"+strings.ToLower(country), strconv.Itoa(user)).Val()) + 1
|
return _position(r, "ripple:leaderboard:"+mode+":"+strings.ToLower(country), user)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _position(r *redis.Client, key string, user int) *int {
|
||||||
|
res := r.ZRevRank(key, strconv.Itoa(user))
|
||||||
|
if res.Err() == redis.Nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
x := int(res.Val()) + 1
|
||||||
|
return &x
|
||||||
}
|
}
|
||||||
|
|
|
@ -293,11 +293,11 @@ LIMIT 1
|
||||||
for modeID, m := range [...]*modeData{&r.STD, &r.Taiko, &r.CTB, &r.Mania} {
|
for modeID, m := range [...]*modeData{&r.STD, &r.Taiko, &r.CTB, &r.Mania} {
|
||||||
m.Level = ocl.GetLevelPrecise(int64(m.TotalScore))
|
m.Level = ocl.GetLevelPrecise(int64(m.TotalScore))
|
||||||
|
|
||||||
if i := leaderboardPosition(md.R, modesToReadable[modeID], r.ID); i != 0 {
|
if i := leaderboardPosition(md.R, modesToReadable[modeID], r.ID); i != nil {
|
||||||
m.GlobalLeaderboardRank = &i
|
m.GlobalLeaderboardRank = i
|
||||||
}
|
}
|
||||||
if i := countryPosition(md.R, modesToReadable[modeID], r.ID, r.Country); i != 0 {
|
if i := countryPosition(md.R, modesToReadable[modeID], r.ID, r.Country); i != nil {
|
||||||
m.CountryLeaderboardRank = &i
|
m.CountryLeaderboardRank = i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user