mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-01 17:00:21 +08:00
perf(usage): 将 status 过滤下推到 SQL 查询层
为 UsageAuditListQuery 新增 statuses 字段,支持在数据库端按状态 筛选用量记录。admin usage summary 路由不再全量拉取后内存过滤, 改为直接查询 pending/streaming 状态的记录。
This commit is contained in:
@@ -480,6 +480,7 @@ pub struct UsageAuditListQuery {
|
||||
pub user_id: Option<String>,
|
||||
pub provider_name: Option<String>,
|
||||
pub model: Option<String>,
|
||||
pub statuses: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Default, serde::Serialize, serde::Deserialize)]
|
||||
|
||||
@@ -1195,10 +1195,22 @@ impl SqlxUsageReadRepository {
|
||||
}
|
||||
if let Some(model) = query.model.as_deref() {
|
||||
builder.push(if has_where { " AND " } else { " WHERE " });
|
||||
has_where = true;
|
||||
builder
|
||||
.push("\"usage\".model = ")
|
||||
.push_bind(model.to_string());
|
||||
}
|
||||
if let Some(statuses) = query.statuses.as_deref() {
|
||||
if !statuses.is_empty() {
|
||||
builder.push(if has_where { " AND " } else { " WHERE " });
|
||||
builder.push("\"usage\".status IN (");
|
||||
let mut separated = builder.separated(", ");
|
||||
for status in statuses {
|
||||
separated.push_bind(status.to_string());
|
||||
}
|
||||
separated.push_unseparated(")");
|
||||
}
|
||||
}
|
||||
|
||||
builder.push(" ORDER BY \"usage\".created_at ASC, \"usage\".request_id ASC");
|
||||
let query = builder.build();
|
||||
|
||||
Reference in New Issue
Block a user