From d7f507916ff850f7af97e7df5e64c3132611b7b6 Mon Sep 17 00:00:00 2001 From: zhx Date: Tue, 26 May 2026 15:35:16 +0800 Subject: [PATCH] Fix user metric update batch ordering --- internal/storage/batch.go | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/internal/storage/batch.go b/internal/storage/batch.go index bf9a00f..49978b9 100644 --- a/internal/storage/batch.go +++ b/internal/storage/batch.go @@ -191,6 +191,20 @@ func (r *MySQLRepository) ApplyContributionBatch(ctx context.Context, tx *sql.Tx } } + for _, c := range negative { + if err := r.ApplyDailyContribution(ctx, tx, c, storageTimezone); err != nil { + return err + } + for _, statTimezone := range statTimezones { + if err := r.ApplyPeriodContribution(ctx, tx, c, statTimezone); err != nil { + return err + } + if err := r.ApplyGamePeriodContribution(ctx, tx, c, statTimezone); err != nil { + return err + } + } + } + for key, totals := range dailyAmounts { if totals.empty() { continue @@ -230,19 +244,6 @@ func (r *MySQLRepository) ApplyContributionBatch(ctx context.Context, tx *sql.Tx return err } } - for _, c := range negative { - if err := r.ApplyDailyContribution(ctx, tx, c, storageTimezone); err != nil { - return err - } - for _, statTimezone := range statTimezones { - if err := r.ApplyPeriodContribution(ctx, tx, c, statTimezone); err != nil { - return err - } - if err := r.ApplyGamePeriodContribution(ctx, tx, c, statTimezone); err != nil { - return err - } - } - } return nil }