mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-03 09:50:21 +08:00
perf(usage): 将 status 过滤下推到 SQL 查询层
为 UsageAuditListQuery 新增 statuses 字段,支持在数据库端按状态 筛选用量记录。admin usage summary 路由不再全量拉取后内存过滤, 改为直接查询 pending/streaming 状态的记录。
This commit is contained in:
@@ -67,14 +67,23 @@ pub(super) async fn maybe_build_local_admin_usage_summary_response(
|
||||
|
||||
let query = request_context.request_query_string.as_deref();
|
||||
let requested_ids = admin_usage_parse_ids(query);
|
||||
let usage = state
|
||||
.list_usage_audits(&UsageAuditListQuery::default())
|
||||
.await?;
|
||||
let list_query = if requested_ids.is_some() {
|
||||
UsageAuditListQuery::default()
|
||||
} else {
|
||||
UsageAuditListQuery {
|
||||
statuses: Some(vec![
|
||||
"pending".to_string(),
|
||||
"streaming".to_string(),
|
||||
]),
|
||||
..Default::default()
|
||||
}
|
||||
};
|
||||
let usage = state.list_usage_audits(&list_query).await?;
|
||||
let mut items: Vec<_> = usage
|
||||
.into_iter()
|
||||
.filter(|item| match requested_ids.as_ref() {
|
||||
Some(ids) => ids.contains(&item.id),
|
||||
None => matches!(item.status.as_str(), "pending" | "streaming"),
|
||||
None => true,
|
||||
})
|
||||
.collect();
|
||||
items.sort_by(|left, right| {
|
||||
|
||||
Reference in New Issue
Block a user