feat(stats): 新增聚合读路径与回填机制并重构 dashboard/usage 读取链路

- 新增 stats_user_summary 及 user_daily_provider/api_format/cost_savings 等聚合表
- 扩展 stats_daily/hourly 有效 token 与响应时间等字段,maintenance runtime 同步写入
- 新增 backfill 模块与 --apply-backfills 命令补齐历史聚合数据
- 重写 dashboard_filters、usage_heatmap、user_rollups 查询改走聚合表
- 同步更新 baseline_v2.sql 与 migration 集,README/dev.sh 补充回填用法
This commit is contained in:
fawney19
2026-04-22 17:29:39 +08:00
parent 063ef02306
commit a5e6bd3b62
45 changed files with 15323 additions and 1039 deletions

View File

@@ -1015,8 +1015,9 @@ pub struct StoredUsageLeaderboardSummary {
pub struct UsageDailyHeatmapQuery {
pub created_from_unix_secs: u64,
pub user_id: Option<String>,
/// When true, exclude rows with status in ('pending', 'streaming') (admin heatmap).
/// When false, only include rows with billing_status = 'settled' and total_cost_usd > 0 (user heatmap).
/// Legacy flag used by admin and user heatmap callers.
/// Both modes exclude non-finalized requests and placeholder providers; user callers also
/// scope by `user_id` when provided.
pub admin_mode: bool,
}