Merge remote-tracking branch 'origin/pr/558'

This commit is contained in:
fawney19
2026-05-25 01:22:03 +08:00
18 changed files with 2099 additions and 117 deletions
@@ -854,19 +854,28 @@ WHERE provider_api_key_id IS NOT NULL AND provider_api_key_id <> ''
let error_message: Option<String> = row.try_get("error_message").map_sql_err()?;
let entry = stats.entry(key_id).or_default();
entry.request_count += 1;
if provider_api_key_usage_is_success(&status, status_code_u16, error_message.as_deref())
{
let is_success = provider_api_key_usage_is_success(
&status,
status_code_u16,
error_message.as_deref(),
);
let is_in_flight = matches!(status.as_str(), "pending" | "streaming");
if is_success {
entry.success_count += 1;
}
if provider_api_key_usage_is_error(&status, status_code_u16, error_message.as_deref()) {
entry.error_count += 1;
}
entry.total_tokens += row.try_get::<i64, _>("total_tokens").map_sql_err()?;
entry.total_cost_usd += row.try_get::<f64, _>("total_cost_usd").map_sql_err()?;
entry.total_response_time_ms += row
.try_get::<Option<i64>, _>("response_time_ms")
.map_sql_err()?
.unwrap_or_default();
if !is_in_flight {
entry.total_tokens += row.try_get::<i64, _>("total_tokens").map_sql_err()?;
entry.total_cost_usd += row.try_get::<f64, _>("total_cost_usd").map_sql_err()?;
}
if is_success {
entry.total_response_time_ms += row
.try_get::<Option<i64>, _>("response_time_ms")
.map_sql_err()?
.unwrap_or_default();
}
entry.last_used_at = entry.last_used_at.max(
row.try_get::<Option<i64>, _>("updated_at_unix_secs")
.map_sql_err()?,