Fix first user metric aggregate insert

This commit is contained in:
zhx 2026-05-25 13:41:18 +08:00
parent 69ecc78db0
commit d67220aa5e
2 changed files with 19 additions and 11 deletions

View File

@ -107,8 +107,10 @@ func (r *MySQLRepository) applyDailyUserGroup(ctx context.Context, tx *sql.Tx, k
_, err = tx.ExecContext(ctx, `
INSERT INTO country_dashboard_daily_metric (
stat_date, date_number, sys_origin, country_code, country_name, refreshed_at
) VALUES (?, ?, ?, ?, ?, NOW())
ON DUPLICATE KEY UPDATE `+column+` = `+column+` + ?, country_name = VALUES(country_name), refreshed_at = NOW()
, `+column+`
) VALUES (?, ?, ?, ?, ?, NOW(), ?)
ON DUPLICATE KEY UPDATE `+column+` = `+column+` + VALUES(`+column+`),
country_name = VALUES(country_name), refreshed_at = NOW()
`, key.day, dateNumber(key.day), key.sysOrigin, key.countryCode, key.countryName, inserted)
return err
}
@ -127,8 +129,10 @@ func (r *MySQLRepository) applyPeriodUserGroup(ctx context.Context, tx *sql.Tx,
INSERT INTO country_dashboard_period_metric (
period_type, period_key, stat_timezone, period_name, period_start_date, period_end_date,
sys_origin, country_code, country_name, refreshed_at
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NOW())
ON DUPLICATE KEY UPDATE `+column+` = `+column+` + ?, country_name = VALUES(country_name), refreshed_at = NOW()
, `+column+`
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), ?)
ON DUPLICATE KEY UPDATE `+column+` = `+column+` + VALUES(`+column+`),
country_name = VALUES(country_name), refreshed_at = NOW()
`, key.periodType, key.periodKey, key.statTimezone, key.periodName, ptrOrNil(key.startDate), ptrOrNil(key.endDate),
key.sysOrigin, key.countryCode, key.countryName, inserted)
return err

View File

@ -23,8 +23,10 @@ func (r *MySQLRepository) applyDailyUserMetric(ctx context.Context, tx *sql.Tx,
_, err = tx.ExecContext(ctx, `
INSERT INTO country_dashboard_daily_metric (
stat_date, date_number, sys_origin, country_code, country_name, refreshed_at
) VALUES (?, ?, ?, ?, ?, NOW())
ON DUPLICATE KEY UPDATE `+column+` = `+column+` + 1, country_name = VALUES(country_name), refreshed_at = NOW()
, `+column+`
) VALUES (?, ?, ?, ?, ?, NOW(), 1)
ON DUPLICATE KEY UPDATE `+column+` = `+column+` + VALUES(`+column+`),
country_name = VALUES(country_name), refreshed_at = NOW()
`, day, dashboard.DateNumber(day), c.SysOrigin, c.Country.Code, c.Country.Name)
return err
}
@ -45,8 +47,10 @@ func (r *MySQLRepository) applyPeriodUserMetric(ctx context.Context, tx *sql.Tx,
INSERT INTO country_dashboard_period_metric (
period_type, period_key, stat_timezone, period_name, period_start_date, period_end_date,
sys_origin, country_code, country_name, refreshed_at
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NOW())
ON DUPLICATE KEY UPDATE `+column+` = `+column+` + 1, country_name = VALUES(country_name), refreshed_at = NOW()
, `+column+`
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), 1)
ON DUPLICATE KEY UPDATE `+column+` = `+column+` + VALUES(`+column+`),
country_name = VALUES(country_name), refreshed_at = NOW()
`, window.Type, window.Key, statTimezone, window.Name, window.StartDate, window.EndDate,
c.SysOrigin, c.Country.Code, c.Country.Name)
return err
@ -129,9 +133,9 @@ INSERT IGNORE INTO country_dashboard_game_period_user_metric (
_, err = tx.ExecContext(ctx, `
INSERT INTO country_dashboard_game_period_metric (
period_type, period_key, stat_timezone, period_name, period_start_date, period_end_date,
sys_origin, country_code, country_name, game_provider, game_id, game_name, refreshed_at
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW())
ON DUPLICATE KEY UPDATE user_count = user_count + 1, country_name = VALUES(country_name),
sys_origin, country_code, country_name, game_provider, game_id, game_name, user_count, refreshed_at
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, NOW())
ON DUPLICATE KEY UPDATE user_count = user_count + VALUES(user_count), country_name = VALUES(country_name),
game_name = VALUES(game_name), refreshed_at = NOW()
`, window.Type, window.Key, statTimezone, window.Name, window.StartDate, window.EndDate,
c.SysOrigin, c.Country.Code, c.Country.Name, c.GameProvider, c.GameID, c.GameName)