From a03ffc8c999c19e468add9fe4f60531121ed29d4 Mon Sep 17 00:00:00 2001 From: erio Date: Mon, 13 Apr 2026 17:38:33 +0800 Subject: [PATCH] fix: change quota notify threshold semantics to "remaining quota" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Threshold now represents remaining quota instead of usage amount: - Fixed ($): threshold=400, limit=1000 → alert when remaining drops to $400 (i.e., usage reaches $600) - Percentage (%): threshold=30%, limit=1000 → alert when remaining drops to 30% (i.e., usage reaches $700) Also: - Rename 告警阈值 → 提醒阈值 in i18n - Widen type dropdown to w-16 for proper $ / % display --- backend/cmd/server/VERSION | 2 +- .../internal/service/balance_notify_service.go | 15 ++++++++++----- .../src/components/account/QuotaNotifyToggle.vue | 2 +- frontend/src/i18n/locales/en.ts | 2 +- frontend/src/i18n/locales/zh.ts | 2 +- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/backend/cmd/server/VERSION b/backend/cmd/server/VERSION index a6c776cd9d..01eddd222f 100644 --- a/backend/cmd/server/VERSION +++ b/backend/cmd/server/VERSION @@ -1 +1 @@ -0.1.110.33 +0.1.110.34 diff --git a/backend/internal/service/balance_notify_service.go b/backend/internal/service/balance_notify_service.go index a912737f91..48c6463353 100644 --- a/backend/internal/service/balance_notify_service.go +++ b/backend/internal/service/balance_notify_service.go @@ -137,13 +137,18 @@ type quotaDim struct { limit float64 } -// resolvedThreshold returns the effective threshold value. -// For percentage type, it computes threshold = limit * percentage / 100. +// resolvedThreshold converts the user-facing "remaining" threshold into a usage-based trigger point. +// The threshold represents how much quota REMAINS when the alert fires: +// - Fixed ($): threshold=400, limit=1000 → fires when usage reaches 600 (remaining drops to 400) +// - Percentage (%): threshold=30, limit=1000 → fires when usage reaches 700 (remaining drops to 30%) func (d quotaDim) resolvedThreshold() float64 { - if d.thresholdType == thresholdTypePercentage && d.limit > 0 { - return d.limit * d.threshold / 100 + if d.limit <= 0 { + return 0 } - return d.threshold + if d.thresholdType == thresholdTypePercentage { + return d.limit * (1 - d.threshold/100) + } + return d.limit - d.threshold } // buildQuotaDims returns the three quota dimensions for notification checking. diff --git a/frontend/src/components/account/QuotaNotifyToggle.vue b/frontend/src/components/account/QuotaNotifyToggle.vue index b86daad703..23979638d7 100644 --- a/frontend/src/components/account/QuotaNotifyToggle.vue +++ b/frontend/src/components/account/QuotaNotifyToggle.vue @@ -42,7 +42,7 @@ const emit = defineEmits<{