update steam profiles only once a day

This commit is contained in:
2022-02-01 19:23:41 +01:00
parent 4b3b8d8053
commit 1aa7cc260a
2 changed files with 28 additions and 13 deletions

16
main.go
View File

@@ -61,6 +61,9 @@ func housekeeping() {
}
// update players from steam
var lastUpdated time.Time
err = rdc.Get(context.Background(), utils.CachePrefix+"last_updated_profiles", lastUpdated)
if err != nil || time.Since(lastUpdated) >= (time.Hour*24) {
tPlayerNeedSteamUpdate, err := db.Player.Query().Where(
player.SteamUpdatedLTE(time.Now().UTC().Add(dur * -1)),
).All(context.Background())
@@ -70,12 +73,23 @@ func housekeeping() {
}
if len(tPlayerNeedSteamUpdate) > 0 {
log.Infof("[HK] Refreshing %d profiles from steam", len(tPlayerNeedSteamUpdate))
log.Infof("[HK] Updating %d profiles from steam", len(tPlayerNeedSteamUpdate))
_, err = utils.PlayerFromSteam(tPlayerNeedSteamUpdate, db, conf.Steam.APIKey, rL)
if err != nil {
log.Warningf("[HK] Unable to update profiles from steam: %v", err)
}
}
err = rdc.Set(&cache.Item{
Ctx: context.Background(),
Key: utils.CachePrefix + "last_updated_profiles",
Value: time.Now().UTC(),
TTL: time.Hour * 24 * 30,
SkipLocalCache: true,
})
if err != nil {
log.Errorf("[HK] Failure setting cache: %v", err)
}
}
// mark matches as vac/gameban
bPlayers, err := db.Player.Query().Select(player.FieldID, player.FieldGameBanDate, player.FieldVacDate).Where(player.Or(player.GameBanDateNotNil(), player.VacDateNotNil())).All(context.Background())

View File

@@ -209,7 +209,8 @@ type (
const (
shareCodeURLEntry = "https://api.steampowered.com/ICSGOPlayers_730/GetNextMatchSharingCode/v1?key=%s&steamid=%d&steamidkey=%s&knowncode=%s"
SideMetaCacheKey = "csgowtfd_side_meta_%d"
CachePrefix = "csgowtfd_"
SideMetaCacheKey = CachePrefix + "side_meta_%d"
)
//goland:noinspection SpellCheckingInspection