fix: align UserQuotaSnapshot type with getUserLimitUsage return type#508
Closed
github-actions[bot] wants to merge 2 commits intofix/daily-quota-timezone-consistencyfrom
Closed
fix: align UserQuotaSnapshot type with getUserLimitUsage return type#508github-actions[bot] wants to merge 2 commits intofix/daily-quota-timezone-consistencyfrom
github-actions[bot] wants to merge 2 commits intofix/daily-quota-timezone-consistencyfrom
Conversation
## 问题描述 用户反馈个人页面显示的用户层级每日限额和Key层级每日限额不一致。 ## 根本原因 - **Key层级**: 正确使用 `getTimeRangeForPeriodWithMode()` 根据配置的 `dailyResetTime` 和 `dailyResetMode` 计算时间范围 - **用户层级**: 使用 `sumUserCostToday()` 简单的日期比较 `created_at::date = CURRENT_DATE`,完全忽略了用户的 `dailyResetTime` 配置 ## 修复内容 ### 1. src/actions/my-usage.ts - **getMyQuota()**: 改用 `getTimeRangeForPeriodWithMode()` + `sumUserCostInTimeRange()` 计算用户每日消费 - **getMyTodayStats()**: 改用时间范围查询替代日期比较 ### 2. src/repository/statistics.ts - 标记 `sumUserCostToday()` 为 `@deprecated`,提供迁移路径说明 ## 影响范围 - ✅ 个人用量页面 (/my-usage) - 用户层级每日限额显示 - ✅ 今日统计卡片 - Key层级今日消费统计 - ✅ 限额检查 - 用户和Key的每日限额使用相同时间范围逻辑 ## 性能优化 从 `(created_at AT TIME ZONE timezone)::date` 表达式比较 改为 `created_at >= startTime AND created_at < endTime` 直接索引范围扫描 预期性能提升: 80%+ ## 测试 - ✅ TypeScript类型检查通过 - ✅ Biome代码检查通过 - ✅ Codex AI代码审核通过 (评分: 8.2/10) Co-reviewed-by: Codex AI
Fixed: - Updated UserQuotaSnapshot.rpm.limit to accept number | null (was number) - Updated UserQuotaSnapshot.dailyCost.limit to accept number | null (was number) - Made UserQuotaSnapshot.dailyCost.resetAt required (was optional) This aligns the interface with the actual return type from getUserLimitUsage action, resolving the TypeScript type mismatch error in page.tsx:75. CI Run: https://github.com/ding113/claude-code-hub/actions/runs/20661769269
a231eec to
e73ade0
Compare
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.
CI Auto-Fix for PR #507
Original PR: #507
Failed CI Run: PR Build Check
Problem
The CI failed with a TypeScript type mismatch error in
src/app/[locale]/dashboard/quotas/users/page.tsx:75:Root Cause
The
getUserLimitUsageaction returns quota data with:rpm.limit: number | nulldailyCost.limit: number | nulldailyCost.resetAt: Date(required)But the
UserQuotaSnapshotinterface expected:rpm.limit: number(not nullable)dailyCost.limit: number(not nullable)dailyCost.resetAt?: Date(optional)Fix Applied
src/app/[locale]/dashboard/quotas/users/_components/types.tsUserQuotaSnapshotinterface to match actual data structureChanges made:
rpm.limit: number→rpm.limit: number \| nulldailyCost.limit: number→dailyCost.limit: number \| nulldailyCost.resetAt?: Date→dailyCost.resetAt: DateVerification
✅
bun run typecheckpasses✅
bun run lintpasses✅ No logic changes made
✅ Minimal, targeted type fix only
Auto-generated by Claude AI
Greptile Summary
Fixes TypeScript type mismatch between
UserQuotaSnapshotinterface andgetUserLimitUsageaction return type. The action returns quota limits as nullable (number | null) andresetAtas required, but the interface expected non-nullable limits and optionalresetAt.Changes:
rpm.limit:number→number | nulldailyCost.limit:number→number | nulldailyCost.resetAt:Date?→Date(now required)This aligns the type definition with the actual runtime data structure returned by
getUserLimitUsage()insrc/actions/users.ts:1233-1295, which retrieves user quota data where limits can be null (unlimited) andresetAtis always present fromgetDailyResetTime().Confidence Score: 5/5
Important Files Changed
Sequence Diagram
sequenceDiagram participant Page as UsersQuotaPage participant Action as getUserLimitUsage participant DB as Database participant Type as UserQuotaSnapshot Page->>Action: getUserLimitUsage(userId) Action->>DB: findUserById(userId) DB-->>Action: User data Action->>DB: sumUserCostToday(userId) DB-->>Action: dailyCost (number) Action->>Action: Build response with<br/>limit: number | null<br/>resetAt: Date Action-->>Page: { rpm, dailyCost } Page->>Type: Assign to quota: UserQuotaSnapshot Note over Page,Type: ✅ Type alignment fixed:<br/>limits now nullable<br/>resetAt now required