fix(dashboard): 修复仪表盘与明细统计数值不一致并重建 cost_savings 聚合

- 统一 dashboard 聚合与 raw 查询的 token 计算,拆分今日节省和周期节省
- cache savings 改用 input price 估算未命中成本,修复历史 cost_savings 偏高
- raw 查询 total_tokens 改用 effective_input + output + cache_creation + cache_read 公式
- 新增独立 backfill 重建历史 cost_savings 聚合表,保留已发布 backfill 不变
This commit is contained in:
mayrain
2026-05-05 17:33:16 +08:00
parent 2f915b33c7
commit 53fa33b0c5
10 changed files with 487 additions and 113 deletions
@@ -1915,7 +1915,7 @@ impl UsageReadRepository for InMemoryUsageReadRepository {
.saturating_add(item.cache_read_input_tokens);
summary.cache_read_cost_usd += item.cache_read_cost_usd;
summary.cache_creation_cost_usd += item.cache_creation_cost_usd;
summary.estimated_full_cost_usd += item.settlement_output_price_per_1m().unwrap_or(0.0)
summary.estimated_full_cost_usd += item.settlement_input_price_per_1m().unwrap_or(0.0)
* item.cache_read_input_tokens as f64
/ 1_000_000.0;
}