cap limit, cache key contains limit

This commit is contained in:
2021-10-23 23:32:36 +02:00
parent e394521755
commit 3124a849f1
2 changed files with 9 additions and 3 deletions

10
main.go
View File

@@ -164,6 +164,12 @@ func getPlayerMeta(w http.ResponseWriter, r *http.Request) {
limit = 4 limit = 4
} }
if limit > 10 {
log.Infof("[GPM] limit out of bounds: %d", limit)
w.WriteHeader(http.StatusBadRequest)
return
}
tPlayer, err := utils.GetPlayer(db, id, conf.Steam.APIKey, nil) tPlayer, err := utils.GetPlayer(db, id, conf.Steam.APIKey, nil)
if err != nil { if err != nil {
log.Infof("[GP] Player not found: %+v", err) log.Infof("[GP] Player not found: %+v", err)
@@ -172,7 +178,7 @@ func getPlayerMeta(w http.ResponseWriter, r *http.Request) {
} }
metaStats := new(utils.MetaStatsResponse) metaStats := new(utils.MetaStatsResponse)
err = rdc.Get(context.Background(), fmt.Sprintf(utils.SideMetaCacheKey, tPlayer.ID), &metaStats) err = rdc.Get(context.Background(), fmt.Sprintf(utils.SideMetaCacheKey, tPlayer.ID, limit), &metaStats)
if err != nil { if err != nil {
metaStats, err = utils.GetMetaStats(tPlayer, db.Lock, limit) metaStats, err = utils.GetMetaStats(tPlayer, db.Lock, limit)
if err != nil { if err != nil {
@@ -183,7 +189,7 @@ func getPlayerMeta(w http.ResponseWriter, r *http.Request) {
err = rdc.Set(&cache.Item{ err = rdc.Set(&cache.Item{
Ctx: context.Background(), Ctx: context.Background(),
Key: fmt.Sprintf(utils.SideMetaCacheKey, tPlayer.ID), Key: fmt.Sprintf(utils.SideMetaCacheKey, tPlayer.ID, limit),
Value: metaStats, Value: metaStats,
TTL: time.Hour * 24 * 30, TTL: time.Hour * 24 * 30,
}) })

View File

@@ -196,7 +196,7 @@ type (
const ( const (
shareCodeURLEntry = "https://api.steampowered.com/ICSGOPlayers_730/GetNextMatchSharingCode/v1?key=%s&steamid=%d&steamidkey=%s&knowncode=%s" shareCodeURLEntry = "https://api.steampowered.com/ICSGOPlayers_730/GetNextMatchSharingCode/v1?key=%s&steamid=%d&steamidkey=%s&knowncode=%s"
SideMetaCacheKey = "csgowtfd_side_meta_%d" SideMetaCacheKey = "csgowtfd_side_meta_%d_%d"
MatchMetaCacheKey = "csgowtfd_match_meta_%d" MatchMetaCacheKey = "csgowtfd_match_meta_%d"
) )