diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2026-02-25 16:26:34 +0100 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2026-02-25 16:26:34 +0100 |
| commit | 443286aabc9d9e433625e0dd99e678754bbc74e5 (patch) | |
| tree | 1d9011757dcd593cc082fd338732173d3117cf2c | |
| parent | dd5a4c1766ed9cadcd5de982f91f407adbd07f40 (diff) | |
fix(reducer): double call on startup
| -rw-r--r-- | common/timer.go | 3 | ||||
| -rw-r--r-- | main.go | 1 | ||||
| -rw-r--r-- | user/level.go | 12 |
3 files changed, 7 insertions, 9 deletions
diff --git a/common/timer.go b/common/timer.go index 553a8fd..aaea326 100644 --- a/common/timer.go +++ b/common/timer.go @@ -9,8 +9,7 @@ import ( func NewTimer(ctx context.Context, d time.Duration, fn func(context.Context, context.CancelFunc)) context.CancelFunc { ctx, cancel := context.WithCancel(ctx) - logger := bot.Logger(ctx).With("module", "timer") - ctx = bot.SetLogger(ctx, logger) + ctx = bot.SetLogger(ctx, bot.Logger(ctx).With("module", "timer")) go func(ctx context.Context, d time.Duration) { ticker := time.NewTicker(d) fn(ctx, cancel) @@ -239,7 +239,6 @@ func setupTimers(ctx context.Context, dg *gokord.Session) { // because logger was never set in this context ctx = bot.SetLogger(ctx, dg.Logger()) - user.PeriodicReducer(ctx, dg) stopPeriodicReducer = common.NewTimer(ctx, d, func(ctx context.Context, _ context.CancelFunc) { user.PeriodicReducer(ctx, dg) diff --git a/user/level.go b/user/level.go index 0b839d1..2a5d494 100644 --- a/user/level.go +++ b/user/level.go @@ -51,25 +51,25 @@ func (c *CopaingCached) onNewLevel(ctx context.Context, dg bot.Session, level ui func PeriodicReducer(ctx context.Context, dg bot.Session) { PeriodicSaver(ctx, dg) - logger := bot.Logger(ctx) - logger.Debug("periodic reducer") + log := bot.Logger(ctx) + log.Debug("periodic reducer") state := GetState(ctx) n := 0 var wg sync.WaitGroup for _, g := range dg.GuildAPI().State.Guilds() { - n++ cfg := config.GetGuildConfig(ctx, g) res := common.GetDB(ctx). Model(&CopaingXP{}). Where("guild_id = ? and created_at < ?", g, exp.TimeStampNDaysBefore(ctx, cfg.DaysXPRemains)). Delete(&CopaingXP{}) if res.Error != nil { - logger.Error("removing old xp", "error", res.Error, "guild", g) + log.Error("removing old xp", "error", res.Error, "guild", g) continue } - logger.Debug("guild cleaned", "guild", g, "rows affected", res.RowsAffected) + n++ + log.Debug("guild cleaned", "guild", g, "rows affected", res.RowsAffected) wg.Go(func() { syncCopaings(ctx, dg, state.Copaings(g)) @@ -78,7 +78,7 @@ func PeriodicReducer(ctx context.Context, dg bot.Session) { wg.Wait() - logger.Debug("periodic reduce finished", "guilds affected", n) + log.Debug("periodic reduce finished", "guilds affected", n) } func syncCopaings(ctx context.Context, dg bot.Session, ccs []CopaingCached) { |
