"backend/internal/handler/vscode:/vscode.git/clone" did not exist on "eb385457b2e878a63457d0739e54bb8cfecc70d3"
Unverified Commit 553a486d authored by Wesley Liddick's avatar Wesley Liddick Committed by GitHub
Browse files

Merge pull request #1171 from wucm667/fix/quota-display-stale-after-reset

fix: quota display shows stale cumulative usage after daily/weekly reset
parents c73374a2 0d45d866
...@@ -276,11 +276,17 @@ func AccountFromServiceShallow(a *service.Account) *Account { ...@@ -276,11 +276,17 @@ func AccountFromServiceShallow(a *service.Account) *Account {
if limit := a.GetQuotaDailyLimit(); limit > 0 { if limit := a.GetQuotaDailyLimit(); limit > 0 {
out.QuotaDailyLimit = &limit out.QuotaDailyLimit = &limit
used := a.GetQuotaDailyUsed() used := a.GetQuotaDailyUsed()
if a.IsDailyQuotaPeriodExpired() {
used = 0
}
out.QuotaDailyUsed = &used out.QuotaDailyUsed = &used
} }
if limit := a.GetQuotaWeeklyLimit(); limit > 0 { if limit := a.GetQuotaWeeklyLimit(); limit > 0 {
out.QuotaWeeklyLimit = &limit out.QuotaWeeklyLimit = &limit
used := a.GetQuotaWeeklyUsed() used := a.GetQuotaWeeklyUsed()
if a.IsWeeklyQuotaPeriodExpired() {
used = 0
}
out.QuotaWeeklyUsed = &used out.QuotaWeeklyUsed = &used
} }
// 固定时间重置配置 // 固定时间重置配置
......
...@@ -1543,6 +1543,24 @@ func isPeriodExpired(periodStart time.Time, dur time.Duration) bool { ...@@ -1543,6 +1543,24 @@ func isPeriodExpired(periodStart time.Time, dur time.Duration) bool {
return time.Since(periodStart) >= dur return time.Since(periodStart) >= dur
} }
// IsDailyQuotaPeriodExpired 检查日配额周期是否已过期(用于显示层判断是否需要将 used 归零)
func (a *Account) IsDailyQuotaPeriodExpired() bool {
start := a.getExtraTime("quota_daily_start")
if a.GetQuotaDailyResetMode() == "fixed" {
return a.isFixedDailyPeriodExpired(start)
}
return isPeriodExpired(start, 24*time.Hour)
}
// IsWeeklyQuotaPeriodExpired 检查周配额周期是否已过期(用于显示层判断是否需要将 used 归零)
func (a *Account) IsWeeklyQuotaPeriodExpired() bool {
start := a.getExtraTime("quota_weekly_start")
if a.GetQuotaWeeklyResetMode() == "fixed" {
return a.isFixedWeeklyPeriodExpired(start)
}
return isPeriodExpired(start, 7*24*time.Hour)
}
// IsQuotaExceeded 检查 API Key 账号配额是否已超限(任一维度超限即返回 true) // IsQuotaExceeded 检查 API Key 账号配额是否已超限(任一维度超限即返回 true)
func (a *Account) IsQuotaExceeded() bool { func (a *Account) IsQuotaExceeded() bool {
// 总额度 // 总额度
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment