fix(my-usage): include active requests in stats summary#1230
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 Walkthrough总体概览PR 将 变更详情Stats Summary 查询与合并重构
评估与相关🎯 3 (中等复杂度) | ⏱️ ~20 分钟 该 PR 涉及查询逻辑重构与去重策略,需要理解数据源并行处理、去重条件(not exists)与合并聚合的相互作用;测试更新反映了额外查询路径的引入。
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add 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.
Code Review
This pull request updates the usage statistics aggregation in getMyStatsSummary to query both messageRequest and usageLedger tables in parallel during a migration period, merging and sorting the results in-memory. It also updates the corresponding unit tests to reflect these changes. There are no review comments, so no additional feedback is provided.
Summary
Fixes the
getMyStatsSummaryfunction to aggregate statistics from both activemessage_requestrows andusage_ledgerrows, ensuring accurate stats during the migration period where both data sources coexist.Problem
PR #1063 switched
getMyStatsSummaryto read exclusively fromusage_ledgerto fix gaps after ledger-only DB reimports. However, this meant active requests that hadn't yet been moved to ledger were excluded from the summary, causing underreported usage statistics during normal operation.Solution
getMyStatsSummarynow queries bothmessage_requestandusage_ledgerin parallel.usage_ledgerquery uses aNOT EXISTSsubquery to exclude ledger rows that have a corresponding activemessage_requestwith the sameidandkey, preventing double-counting.modelBreakdownvia the newmergeStatsSummaryRowshelper.?? 0fallbacks in the output mapping to preventnullfrom appearing in the final stats.Related
Changes
Core Changes
src/actions/my-usage.ts— Added dual-querygetMyStatsSummarywithmergeStatsSummaryRowshelper and ledger deduplicationTest Updates
tests/unit/actions/my-usage-token-aggregation.test.ts— Updated to expect 2 query selections and verify precision across both pathsTesting
Automated Tests
my-usage-token-aggregation.test.ts)Validation
Checklist
Description enhanced by Claude AI