removed rateLimit from http router requests

improved logging
This commit is contained in:
2021-10-20 00:11:42 +02:00
parent 6e951183de
commit df33974b49
12 changed files with 49 additions and 2752 deletions

View File

@@ -96,17 +96,6 @@ type Rank struct {
New int `json:"new,omitempty"`
}
type HitGroup struct {
Head uint `json:"head,omitempty"`
Chest uint `json:"chest,omitempty"`
Stomach uint `json:"stomach,omitempty"`
LeftArm uint `json:"left_arm,omitempty"`
RightArm uint `json:"right_arm,omitempty"`
LeftLeg uint `json:"left_leg,omitempty"`
RightLeg uint `json:"right_leg,omitempty"`
Gear uint `json:"gear,omitempty"`
}
type UD struct {
HE uint `json:"he,omitempty"`
Flames uint `json:"flames,omitempty"`
@@ -116,10 +105,9 @@ type UD struct {
}
type Damage struct {
Enemy uint `json:"enemy,omitempty"`
Team uint `json:"team,omitempty"`
UD *UD `json:"ud,omitempty"`
HitGroup *HitGroup `json:"hit_group,omitempty"`
Enemy uint `json:"enemy,omitempty"`
Team uint `json:"team,omitempty"`
UD *UD `json:"ud,omitempty"`
}
type SelfTeamEnemy struct {
@@ -270,7 +258,7 @@ func IsAuthCodeValid(player *ent.Player, lock *sync.RWMutex, apiKey string, shar
var err error
if shareCode == "" {
lock.RLock()
tMatch, err = player.QueryMatches().Order(ent.Desc(match.FieldDate)).First(context.Background())
tMatch, err = player.QueryMatches().Order(ent.Asc(match.FieldDate)).Limit(1).Only(context.Background())
lock.RUnlock()
if err != nil {
return false, err
@@ -292,7 +280,7 @@ func IsAuthCodeValid(player *ent.Player, lock *sync.RWMutex, apiKey string, shar
func GetNewShareCodesForPlayer(player *ent.Player, lock *sync.RWMutex, apiKey string, rl ratelimit.Limiter) ([]string, error) {
lock.RLock()
tMatch, err := player.QueryMatches().Order(ent.Desc(match.FieldDate)).First(context.Background())
tMatch, err := player.QueryMatches().Order(ent.Desc(match.FieldDate)).Limit(1).Only(context.Background())
lock.RUnlock()
if err != nil {
return nil, err
@@ -327,7 +315,9 @@ func getNextShareCode(lastCode string, apiKey string, authCode string, steamId u
return "", fmt.Errorf("invalid arguments")
}
rl.Take()
if rl != nil {
rl.Take()
}
log.Debugf("[SC] STEAMPI with %s", fmt.Sprintf(shareCodeURLEntry, "REDACTED", steamId, "REDACTED", lastCode))
r, err := http.Get(fmt.Sprintf(shareCodeURLEntry, apiKey, steamId, authCode, lastCode))
if err != nil {
@@ -397,7 +387,9 @@ func GetPlayerFromVanityURL(db *DBWithLock, id string, apiKey string, rl ratelim
if err == nil {
return tPlayer, nil
} else {
rl.Take()
if rl != nil {
rl.Take()
}
resp, err := steamapi.ResolveVanityURL(id, apiKey)
if err != nil {
return nil, err
@@ -452,7 +444,9 @@ func UpdatePlayerFromSteam(players []*ent.Player, db *ent.Client, apiKey string,
log.Infof("[STEAM] Getting %d profiles from steam", len(idsToUpdate))
rl.Take()
if rl != nil {
rl.Take()
}
playerSum, err := steamapi.GetPlayerSummaries(idsToUpdate, apiKey)
if err != nil {
return nil, err
@@ -486,7 +480,9 @@ func UpdatePlayerFromSteam(players []*ent.Player, db *ent.Client, apiKey string,
nPlayers = append(nPlayers, tPlayer)
}
rl.Take()
if rl != nil {
rl.Take()
}
bans, err := steamapi.GetPlayerBans(idsToUpdate, apiKey)
if err != nil {
return nil, err