Skip to content

Fix fixed weekly quota usage after switching from rolling reset#3018

Open
Zbl1007 wants to merge 1 commit into
Wei-Shaw:mainfrom
Zbl1007:openmeta/2989-0
Open

Fix fixed weekly quota usage after switching from rolling reset#3018
Zbl1007 wants to merge 1 commit into
Wei-Shaw:mainfrom
Zbl1007:openmeta/2989-0

Conversation

@Zbl1007
Copy link
Copy Markdown

@Zbl1007 Zbl1007 commented Jun 3, 2026

Summary

  • Normalize fixed daily and weekly account quota windows during account create/update.
  • Clear stale preserved rolling quota starts when a fixed reset window is active so the dashboard shows current-window usage correctly.
  • Add regression coverage for fixed weekly reset edits and quota window normalization.

Fixes #2989

Tests

  • make -C backend test-unit
  • make -C backend build

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 3, 2026

All contributors have signed the CLA. ✅
Posted by the CLA Assistant Lite bot.

@Zbl1007
Copy link
Copy Markdown
Author

Zbl1007 commented Jun 3, 2026

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Jun 3, 2026
@Zbl1007 Zbl1007 marked this pull request as ready for review June 3, 2026 17:15
Copilot AI review requested due to automatic review settings June 3, 2026 17:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds normalization logic to align daily/weekly quota usage windows when switching an account from rolling to fixed resets, preventing legacy “rolling start” timestamps from making current usage appear expired.

Changes:

  • Introduces NormalizeFixedQuotaWindows to reset stale quota_*_start / quota_*_used values for fixed reset mode.
  • Invokes normalization during account create/update flows.
  • Adds unit/integration tests covering weekly fixed reset normalization behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
backend/internal/service/account.go Adds normalization helper and supporting time parsing for quota window starts.
backend/internal/service/admin_service.go Calls normalization during CreateAccount/UpdateAccount when Extra is updated.
backend/internal/service/account_quota_reset_test.go Adds unit tests for weekly window normalization.
backend/internal/service/admin_service_overages_test.go Adds service-level test ensuring UpdateAccount clears legacy rolling weekly usage on fixed reset.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +2049 to +2057
now := time.Now()
tzName, _ := extra["quota_reset_timezone"].(string)
if tzName == "" {
tzName = "UTC"
}
tz, err := time.LoadLocation(tzName)
if err != nil {
tz = time.UTC
}
tz = time.UTC
}

if mode, _ := extra["quota_daily_reset_mode"].(string); mode == "fixed" && parseExtraFloat64(extra["quota_daily_limit"]) > 0 {
}
}

if mode, _ := extra["quota_weekly_reset_mode"].(string); mode == "fixed" && parseExtraFloat64(extra["quota_weekly_limit"]) > 0 {
Comment on lines +2421 to +2431
func parseExtraTime(value any) time.Time {
if s, ok := value.(string); ok {
if t, err := time.Parse(time.RFC3339Nano, s); err == nil {
return t
}
if t, err := time.Parse(time.RFC3339, s); err == nil {
return t
}
}
return time.Time{}
}
Comment on lines +406 to +408
now := time.Now().UTC()
daysSinceMonday := (int(now.Weekday()) + 6) % 7
currentWeekStart := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.UTC).AddDate(0, 0, -daysSinceMonday)
Comment on lines +158 to +160
now := time.Now().UTC()
daysSinceMonday := (int(now.Weekday()) + 6) % 7
currentWeekStart := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.UTC).AddDate(0, 0, -daysSinceMonday)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

额度控制统计异常:日消耗正常累加,但周限额进度始终显示为 0%

2 participants