Fix fixed weekly quota usage after switching from rolling reset#3018
Open
Zbl1007 wants to merge 1 commit into
Open
Fix fixed weekly quota usage after switching from rolling reset#3018Zbl1007 wants to merge 1 commit into
Zbl1007 wants to merge 1 commit into
Conversation
Contributor
|
All contributors have signed the CLA. ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
Contributor
There was a problem hiding this comment.
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
NormalizeFixedQuotaWindowsto reset stalequota_*_start/quota_*_usedvalues 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2989
Tests