fix(admin): 修复 usage 观测全表扫描并下推聚合查询

- 收紧 admin usage/stats 默认时间范围和 active 轮询查询
- 将 summary/records/aggregation/time-series/leaderboard 下推到 SQL 侧
- 统一前端时间参数并补齐 admin usage/stats 回归测试
This commit is contained in:
fawney19
2026-04-16 17:41:32 +08:00
parent 10605d9fb0
commit 65cd9dc3e5
28 changed files with 3085 additions and 381 deletions

View File

@@ -45,6 +45,56 @@ impl AppState {
.map_err(|err| GatewayError::Internal(err.to_string()))
}
pub(crate) async fn count_usage_audits(
&self,
query: &usage::UsageAuditListQuery,
) -> Result<u64, GatewayError> {
self.data
.count_usage_audits(query)
.await
.map_err(|err| GatewayError::Internal(err.to_string()))
}
pub(crate) async fn aggregate_usage_audits(
&self,
query: &usage::UsageAuditAggregationQuery,
) -> Result<Vec<usage::StoredUsageAuditAggregation>, GatewayError> {
self.data
.aggregate_usage_audits(query)
.await
.map_err(|err| GatewayError::Internal(err.to_string()))
}
pub(crate) async fn summarize_usage_audits(
&self,
query: &usage::UsageAuditSummaryQuery,
) -> Result<usage::StoredUsageAuditSummary, GatewayError> {
self.data
.summarize_usage_audits(query)
.await
.map_err(|err| GatewayError::Internal(err.to_string()))
}
pub(crate) async fn summarize_usage_time_series(
&self,
query: &usage::UsageTimeSeriesQuery,
) -> Result<Vec<usage::StoredUsageTimeSeriesBucket>, GatewayError> {
self.data
.summarize_usage_time_series(query)
.await
.map_err(|err| GatewayError::Internal(err.to_string()))
}
pub(crate) async fn summarize_usage_leaderboard(
&self,
query: &usage::UsageLeaderboardQuery,
) -> Result<Vec<usage::StoredUsageLeaderboardSummary>, GatewayError> {
self.data
.summarize_usage_leaderboard(query)
.await
.map_err(|err| GatewayError::Internal(err.to_string()))
}
pub(crate) async fn summarize_usage_daily_heatmap(
&self,
query: &UsageDailyHeatmapQuery,