feat(account): add daily/weekly periodic quota limits for API Key accounts#841
Open
touwaeriol wants to merge 5 commits intoWei-Shaw:mainfrom
Open
feat(account): add daily/weekly periodic quota limits for API Key accounts#841touwaeriol wants to merge 5 commits intoWei-Shaw:mainfrom
touwaeriol wants to merge 5 commits intoWei-Shaw:mainfrom
Conversation
…ounts Extend the existing total quota limit with daily and weekly periodic dimensions. Each dimension is independently configurable and uses lazy reset — when the period expires, usage is automatically reset to zero on the next increment. Any dimension exceeding its limit will pause the account from scheduling. Backend: - Add GetQuotaDailyLimit/Used, GetQuotaWeeklyLimit/Used, HasAnyQuotaLimit - Rewrite IncrementQuotaUsed with atomic CTE SQL for 3-dimension update - Rewrite ResetQuotaUsed to clear all dimensions and period timestamps - Update postUsageBilling to use HasAnyQuotaLimit() - Preserve daily/weekly used values on account edit Frontend: - Refactor QuotaLimitCard from single v-model to 3-dimension props - Add QuotaBadge component for compact D/W/$ display - Update AccountCapacityCell with per-dimension badges - Update Create/Edit modals with daily/weekly quota fields - Update AccountActionMenu hasQuotaLimit to check all dimensions - Add i18n strings for daily/weekly/total quota labels Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The recent upstream commit added allow_messages_dispatch to the Group DTO but did not update the API contract test expectation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Show a semi-transparent blue rectangle overlay while dragging to select rows, matching the project's primary color theme with dark mode support. The box spans the full table width from drag start to current mouse position. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
背景 / Background
当前 API Key 账号仅支持设置总额度限制(
quota_limit),缺乏周期性(日/周)配额维度。用户需要更灵活的配额控制——例如设置每日限额防止短时间内消耗过多,或设置周限额进行周期性预算管理。Currently API Key accounts only support a total quota limit (
quota_limit), lacking periodic (daily/weekly) quota dimensions. Users need more flexible quota controls — e.g., daily limits to prevent excessive consumption in short periods, or weekly limits for periodic budget management.目的 / Purpose
为 API Key 账号新增日限额和周限额两个独立维度,与现有总限额共存。三个维度可独立配置,任一维度超限即暂停账号调度。日/周限额采用滚动周期+懒重置机制(周期过期后在下次计费时自动重置为 0),无需后台定时任务。
Add daily and weekly quota limit dimensions to API Key accounts, coexisting with the existing total quota limit. All three dimensions are independently configurable; exceeding any one pauses account scheduling. Daily/weekly limits use rolling periods with lazy reset (automatically reset to zero on next billing after period expiry), requiring no background cron jobs.
改动内容 / Changes
后端 / Backend
GetQuotaDailyLimit/Used、GetQuotaWeeklyLimit/Used、HasAnyQuotaLimit、getExtraFloat64、getExtraTime、isPeriodExpiredIsQuotaExceeded:检查总/日/周三个维度,任一超限返回 trueIncrementQuotaUsedSQL:原子更新三维度用量,日/周额度在周期过期时自动重置(inline UPDATE 避免 CTE 快照在 READ COMMITTED 下丢失更新)ResetQuotaUsedSQL:重置所有维度用量并删除周期时间戳postUsageBilling:条件从GetQuotaLimit() > 0改为HasAnyQuotaLimit()admin_service.go:编辑账号时保留quota_daily_used/start、quota_weekly_used/start避免意外重置GetQuotaDailyLimit/Used,GetQuotaWeeklyLimit/Used,HasAnyQuotaLimit,getExtraFloat64,getExtraTime,isPeriodExpiredIsQuotaExceeded: checks total/daily/weekly — any dimension exceeding returns trueIncrementQuotaUsedSQL: atomically updates 3 dimensions; daily/weekly auto-reset on period expiry (inline UPDATE to avoid CTE snapshot lost-update under READ COMMITTED)ResetQuotaUsedSQL: resets all dimensions and removes period timestampspostUsageBilling: condition changed fromGetQuotaLimit() > 0toHasAnyQuotaLimit()admin_service.go: preservequota_daily_used/start,quota_weekly_used/starton account edit前端 / Frontend
QuotaLimitCard.vue:从单一v-model改为三个独立 props(totalLimit/dailyLimit/weeklyLimit),支持同时配置多个维度QuotaBadge.vue:通用配额徽章组件,显示$used/$limit及颜色状态(绿/黄/红)AccountCapacityCell.vue:使用QuotaBadge显示 D(日)/W(周)/$(总)三维度徽章EditAccountModal.vue/CreateAccountModal.vue:新增日/周配额输入字段AccountActionMenu.vue:hasQuotaLimit检查扩展为三维度QuotaLimitCard.vue: refactored from singlev-modelto 3 independent props (totalLimit/dailyLimit/weeklyLimit), supporting simultaneous multi-dimension configurationQuotaBadge.vue: reusable quota badge component showing$used/$limitwith color-coded status (green/yellow/red)AccountCapacityCell.vue: usesQuotaBadgeto display D(daily)/W(weekly)/$(total) dimension badgesEditAccountModal.vue/CreateAccountModal.vue: added daily/weekly quota input fieldsAccountActionMenu.vue:hasQuotaLimitcheck extended to three dimensions技术细节 / Technical Details
懒重置机制 / Lazy Reset Mechanism
日/周配额不使用后台定时任务重置,而是在
IncrementQuotaUsedSQL 中内联处理:quota_daily_start+ 24h 是否 <= NOW()quota_daily_used = $amount,更新quota_daily_start为当前 UTC 时间quota_daily_used += $amountDaily/weekly quotas use inline lazy reset in
IncrementQuotaUsedSQL instead of background cron:quota_daily_start+ 24h <= NOW()quota_daily_used = $amount, updatequota_daily_startto current UTCquota_daily_used += $amount