fix(groups): preserve group traffic totals on global client reset (#7094)

Adjust group baselines before clearing client counters so group usage survives a global reset.
This commit is contained in:
Benjamin Mitchell
2026-11-12 14:36:22 -08:00
committed by GitHub
parent efe768521d
commit 7da8fd23be
3 changed files with 49 additions and 0 deletions
+12
View File
@@ -67,6 +67,14 @@ func adjustGroupBaselinesForRemovedTraffic(tx *gorm.DB, emails []string) error {
return shiftGroupBaselines(tx, emails, -1)
}
func adjustAllGroupBaselinesForRemovedTraffic(tx *gorm.DB) error {
totals, err := sumGroupTraffic(tx, "c.group_name <> ''")
if err != nil {
return err
}
return applyGroupBaselineShift(tx, totals, -1)
}
// adjustGroupBaselinesForRestoredTraffic shifts group baselines up by counters an
// import restored, so usage from before the import never enters a group total.
func adjustGroupBaselinesForRestoredTraffic(tx *gorm.DB, emails []string) error {
@@ -92,6 +100,10 @@ func shiftGroupBaselines(tx *gorm.DB, emails []string, sign int64) error {
}
}
}
return applyGroupBaselineShift(tx, totals, sign)
}
func applyGroupBaselineShift(tx *gorm.DB, totals map[string]*groupCounters, sign int64) error {
for name, d := range totals {
if d.up == 0 && d.down == 0 {
continue