added endpoint for sidebar metastats

This commit is contained in:
2021-10-23 21:53:06 +02:00
parent cd6cd6bf58
commit 9ebebe18af
3 changed files with 287 additions and 14 deletions

View File

@@ -11,6 +11,7 @@ import (
"github.com/an0nfunc/go-steam/v3/netutil"
"github.com/an0nfunc/go-steam/v3/protocol/gamecoordinator"
"github.com/an0nfunc/go-steam/v3/protocol/steamlang"
"github.com/go-redis/cache/v8"
log "github.com/sirupsen/logrus"
"go.uber.org/ratelimit"
"google.golang.org/protobuf/proto"
@@ -37,6 +38,7 @@ type DemoMatchLoaderConfig struct {
Worker int
ApiKey string
RateLimit ratelimit.Limiter
Cache *cache.Cache
}
type DemoMatchLoader struct {
@@ -53,6 +55,7 @@ type DemoMatchLoader struct {
dp *DemoParser
parseDemo chan *Demo
parseMap map[string]bool
cache *cache.Cache
}
func AccountId2SteamId(accId uint32) uint64 {
@@ -172,6 +175,7 @@ func (d *DemoMatchLoader) Setup(config *DemoMatchLoaderConfig) error {
d.db = config.Db
d.dp = &DemoParser{}
d.parseMap = map[string]bool{}
d.cache = config.Cache
err := d.dp.Setup(config.Db, config.Lock, config.Worker)
if err != nil {
return err
@@ -486,6 +490,12 @@ func (d *DemoMatchLoader) gcWorker(apiKey string, rl ratelimit.Limiter) {
}
}
// clear cache for player
for _, p := range players {
_ = d.cache.Delete(context.Background(), fmt.Sprintf(utils.SideMetaCacheKey, p.ID))
_ = d.cache.Delete(context.Background(), fmt.Sprintf(utils.MatchMetaCacheKey, p.ID))
}
err = d.dp.ParseDemo(demo)
if err != nil {
log.Warningf("[DL] Can't queue demo %d for parsing: %v", demo.MatchId, err)