mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-08 10:27:46 +08:00
修复 ChatGPT Web 生图发起即扣额度
This commit is contained in:
@@ -389,19 +389,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()?,
|
||||
|
||||
Reference in New Issue
Block a user