sped up /meta
This commit is contained in:
47
main.go
47
main.go
@@ -178,9 +178,9 @@ func getPlayerMeta(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
metaStats := new(utils.MetaStatsResponse)
|
||||
err = rdc.Get(context.Background(), fmt.Sprintf(utils.SideMetaCacheKey, tPlayer.ID, limit), &metaStats)
|
||||
err = rdc.Get(context.Background(), fmt.Sprintf(utils.SideMetaCacheKey, tPlayer.ID), &metaStats)
|
||||
if err != nil {
|
||||
metaStats, err = utils.GetMetaStats(tPlayer, db.Lock, limit)
|
||||
metaStats, err = utils.GetMetaStats(tPlayer, db.Lock)
|
||||
if err != nil {
|
||||
log.Infof("[GPM] Unable to get MetaStats: %v", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
@@ -189,7 +189,7 @@ func getPlayerMeta(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
err = rdc.Set(&cache.Item{
|
||||
Ctx: context.Background(),
|
||||
Key: fmt.Sprintf(utils.SideMetaCacheKey, tPlayer.ID, limit),
|
||||
Key: fmt.Sprintf(utils.SideMetaCacheKey, tPlayer.ID),
|
||||
Value: metaStats,
|
||||
TTL: time.Hour * 24 * 30,
|
||||
})
|
||||
@@ -203,6 +203,47 @@ func getPlayerMeta(w http.ResponseWriter, r *http.Request) {
|
||||
log.Debugf("[GPM] SideMetaStats for %d from cache", tPlayer.ID)
|
||||
}
|
||||
|
||||
if len(metaStats.BestMates) > limit {
|
||||
metaStats.BestMates = metaStats.BestMates[:limit]
|
||||
}
|
||||
if len(metaStats.MostMates) > limit {
|
||||
metaStats.MostMates = metaStats.MostMates[:limit]
|
||||
}
|
||||
if len(metaStats.WeaponDmg) > limit {
|
||||
metaStats.WeaponDmg = metaStats.WeaponDmg[:limit]
|
||||
}
|
||||
|
||||
for _, wD := range metaStats.WeaponDmg {
|
||||
if _, exist := metaStats.EqMap[wD.Eq]; !exist {
|
||||
metaStats.EqMap[wD.Eq] = common.EquipmentType(wD.Eq).String()
|
||||
}
|
||||
}
|
||||
|
||||
for _, p := range append(metaStats.BestMates, metaStats.MostMates...) {
|
||||
if p.Player.Name == "" {
|
||||
tP, err := db.Client.Player.Get(context.Background(), p.Player.SteamID64)
|
||||
if err != nil {
|
||||
log.Warningf("[GPM] Failure getting player: %v", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
p.Player.Avatar = tP.Avatar
|
||||
p.Player.Name = tP.Name
|
||||
p.Player.VAC = !tP.VacDate.IsZero()
|
||||
p.Player.Tracked = tP.AuthCode != ""
|
||||
p.Player.GameBan = !tP.GameBanDate.IsZero()
|
||||
p.Player.VanityURL = tP.VanityURLReal
|
||||
|
||||
if !tP.GameBanDate.IsZero() {
|
||||
p.Player.GameBanDate = tP.GameBanDate.Unix()
|
||||
}
|
||||
|
||||
if !tP.VacDate.IsZero() {
|
||||
p.Player.VACDate = tP.VacDate.Unix()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
err = utils.SendJSON(metaStats, w)
|
||||
if err != nil {
|
||||
log.Errorf("[GPM] Unable to marshal JSON: %v", err)
|
||||
|
Reference in New Issue
Block a user