mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 01:10:23 +08:00
fix(usage,pool): 修复号池最后使用时间不更新
统一在 ProviderAPIKey 累计更新时刷新 last_used_at/updated_at,即使 token/cost 增量为 0。 补充回归测试:覆盖 zero delta 场景和 provider_api_key_id 为空时跳过更新。
This commit is contained in:
@@ -97,19 +97,20 @@ def _increment_provider_api_key_totals(
|
||||
total_tokens: int = 0,
|
||||
total_cost: float = 0.0,
|
||||
) -> None:
|
||||
"""原子递增 ProviderAPIKey 的累计 Token/成本。"""
|
||||
"""原子更新 ProviderAPIKey 统计并刷新最后使用时间。"""
|
||||
if not provider_api_key_id:
|
||||
return
|
||||
|
||||
from sqlalchemy import func as sql_func
|
||||
token_increment = int(total_tokens or 0)
|
||||
cost_increment = to_money_decimal(total_cost)
|
||||
|
||||
if token_increment <= 0 and cost_increment <= 0:
|
||||
return
|
||||
|
||||
from sqlalchemy import update
|
||||
|
||||
values: dict[str, Any] = {}
|
||||
values: dict[str, Any] = {
|
||||
"last_used_at": sql_func.now(),
|
||||
"updated_at": sql_func.now(),
|
||||
}
|
||||
if token_increment > 0:
|
||||
values["total_tokens"] = ProviderAPIKey.total_tokens + token_increment
|
||||
if cost_increment > 0:
|
||||
|
||||
Reference in New Issue
Block a user