Repository navigation
Conversation
Add cache_read_tokens and cache_write_tokens to QuotaData model, extracting from Log.other on the write path. Propagate through rankings service. Dashboard gets Cache Read and Cache Hit Rate stat cards plus enriched chart tooltips. Rankings leaderboard shows cache total and hit rate percentage per model.
WalkthroughAdds cache read/write token tracking end-to-end: consume-log recording extracts cache tokens, quota data models persist and aggregate them, ranking queries and the rankings service propagate the values, and dashboard/rankings frontend components with new i18n strings display cache hit rates and totals. ChangesCache Token Metrics End-to-End
Estimated code review effort: 3 (Moderate) | ~30 minutes Possibly related PRs
Suggested reviewers:
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
web/default/src/features/dashboard/lib/charts.ts (1)
729-752: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCache hit rate formula duplicated between this tooltip and the dashboard stat card.
The
(CacheRead / Tokens) * 100calculation here is re-implemented independently inuse-dashboard-config.tsx'scacheHitRatecard (viasafeDivide). Both need to stay semantically identical (cache-read share of total tokens); extracting a small shared helper (e.g.calculateCacheHitRate(read, total)) would prevent the two from silently drifting if precision or the guard condition changes later.♻️ Proposed shared helper
// e.g. in a shared lib file export function calculateCacheHitRatePct(cacheRead: number, totalTokens: number): number { if (totalTokens <= 0) return 0 return (cacheRead / totalTokens) * 100 }Then in
charts.ts:- value: (datum: Record<string, unknown>) => { - const tokens = Number(datum?.Tokens) || 0 - const read = Number(datum?.CacheRead) || 0 - if (tokens <= 0) return '0%' - return `${((read / tokens) * 100).toFixed(1)}%` - }, + value: (datum: Record<string, unknown>) => { + const tokens = Number(datum?.Tokens) || 0 + const read = Number(datum?.CacheRead) || 0 + return `${calculateCacheHitRatePct(read, tokens).toFixed(1)}%` + },🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@web/default/src/features/dashboard/lib/charts.ts` around lines 729 - 752, The cache hit rate logic is duplicated in the tooltip formatter inside charts.ts and the cacheHitRate card in use-dashboard-config.tsx, so both should use the same shared helper. Extract the percentage calculation into a small function such as calculateCacheHitRatePct(cacheRead, totalTokens) and call it from both the charts tooltip value formatter and the dashboard stat card logic (including any safeDivide-based path) so the guard condition and precision stay identical.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@web/default/src/features/rankings/components/model-leaderboard.tsx`:
- Around line 113-116: The vendor prefix text in model-leaderboard’s row
rendering is hardcoded, so this React component is still partially untranslated.
Update the component to use react-i18next by calling useTranslation() in
model-leaderboard.tsx and render the “by” prefix with t() alongside the existing
VendorLink/row.vendor output, matching the surrounding localized cache labels.
---
Nitpick comments:
In `@web/default/src/features/dashboard/lib/charts.ts`:
- Around line 729-752: The cache hit rate logic is duplicated in the tooltip
formatter inside charts.ts and the cacheHitRate card in
use-dashboard-config.tsx, so both should use the same shared helper. Extract the
percentage calculation into a small function such as
calculateCacheHitRatePct(cacheRead, totalTokens) and call it from both the
charts tooltip value formatter and the dashboard stat card logic (including any
safeDivide-based path) so the guard condition and precision stay identical.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 6b6e3902-59e2-40bf-a0ba-da58fcaa662c
📒 Files selected for processing (13)
model/log.gomodel/usedata.gomodel/usedata_rankings.goservice/rankings.goweb/default/src/features/dashboard/components/models/log-stat-cards.tsxweb/default/src/features/dashboard/hooks/use-dashboard-config.tsxweb/default/src/features/dashboard/lib/charts.tsweb/default/src/features/dashboard/lib/stats.tsweb/default/src/features/dashboard/types.tsweb/default/src/features/rankings/components/model-leaderboard.tsxweb/default/src/features/rankings/types.tsweb/default/src/i18n/locales/en.jsonweb/default/src/i18n/locales/zh.json
| by{' '} | ||
| <VendorLink vendor={row.vendor}> | ||
| {row.vendor.toLowerCase()} | ||
| </VendorLink> |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Localize the vendor prefix.
by is user-facing text in this React component, so this row stays partially untranslated even though the surrounding cache labels already go through t().
Suggested fix
- by{' '}
+ {t('by')}{' '}As per coding guidelines, "Frontend UI text must support i18n with i18next/react-i18next" and "web/default/**/*.{ts,tsx}: React components must call useTranslation() and render user-facing text with t()."
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| by{' '} | |
| <VendorLink vendor={row.vendor}> | |
| {row.vendor.toLowerCase()} | |
| </VendorLink> | |
| {t('by')}{' '} | |
| <VendorLink vendor={row.vendor}> | |
| {row.vendor.toLowerCase()} | |
| </VendorLink> |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@web/default/src/features/rankings/components/model-leaderboard.tsx` around
lines 113 - 116, The vendor prefix text in model-leaderboard’s row rendering is
hardcoded, so this React component is still partially untranslated. Update the
component to use react-i18next by calling useTranslation() in
model-leaderboard.tsx and render the “by” prefix with t() alongside the existing
VendorLink/row.vendor output, matching the surrounding localized cache labels.
Source: Coding guidelines
51fdfc5 to
2b6f1df
Compare
Add cache_read_tokens and cache_write_tokens to QuotaData model, extracting from Log.other on the write path. Propagate through rankings service. Dashboard gets Cache Read and Cache Hit Rate stat cards plus enriched chart tooltips. Rankings leaderboard shows cache total and hit rate percentage per model.
📝 变更描述 / Description
添加/dashboard/models数据看板缓存命中情况
添加排行榜界面模型缓存命中情况
🚀 变更类型 / Type of change
✅ 提交前检查项 / Checklist
📸 运行证明 / Proof of Work
Summary by CodeRabbit
New Features
Bug Fixes