Improve gateway transport and usage runtime

This commit is contained in:
elky
2026-06-25 22:36:27 +08:00
parent d336d1a7fa
commit 6f00e9fc67
112 changed files with 12456 additions and 1387 deletions
@@ -12,18 +12,43 @@ const DAILY_QUOTA_EPSILON_USD: f64 = 0.000_000_01;
pub(crate) async fn resolve_wallet_auth_gate(
state: &AppState,
auth_snapshot: &GatewayAuthApiKeySnapshot,
) -> Result<Option<WalletAccessDecision>, GatewayError> {
resolve_wallet_auth_gate_with_cache(state, auth_snapshot, true).await
}
pub(crate) async fn resolve_wallet_auth_gate_uncached(
state: &AppState,
auth_snapshot: &GatewayAuthApiKeySnapshot,
) -> Result<Option<WalletAccessDecision>, GatewayError> {
resolve_wallet_auth_gate_with_cache(state, auth_snapshot, false).await
}
async fn resolve_wallet_auth_gate_with_cache(
state: &AppState,
auth_snapshot: &GatewayAuthApiKeySnapshot,
use_cache: bool,
) -> Result<Option<WalletAccessDecision>, GatewayError> {
if !state.has_wallet_data_reader() {
return Ok(None);
}
let wallet = state
.read_wallet_snapshot_for_auth(
&auth_snapshot.user_id,
&auth_snapshot.api_key_id,
auth_snapshot.api_key_is_standalone,
)
.await?;
let wallet = if use_cache {
state
.read_wallet_snapshot_for_auth(
&auth_snapshot.user_id,
&auth_snapshot.api_key_id,
auth_snapshot.api_key_is_standalone,
)
.await?
} else {
state
.read_wallet_snapshot_for_auth_uncached(
&auth_snapshot.user_id,
&auth_snapshot.api_key_id,
auth_snapshot.api_key_is_standalone,
)
.await?
};
let decision = match wallet.as_ref() {
Some(wallet) => map_wallet_snapshot(wallet).access_decision(false),
@@ -1,5 +1,7 @@
mod access;
mod quota;
pub(crate) use access::{local_rejection_from_wallet_access, resolve_wallet_auth_gate};
pub(crate) use access::{
local_rejection_from_wallet_access, resolve_wallet_auth_gate, resolve_wallet_auth_gate_uncached,
};
pub(crate) use quota::spawn_provider_quota_reset_worker;