perf(gateway): 为 dashboard 接口添加短时响应缓存

新增 DashboardResponseCache,对 stats/daily_stats/provider_status
三个接口按用户维度缓存 15-30 秒,减少重复数据库查询。
This commit is contained in:
fawney19
2026-04-15 03:03:20 +08:00
parent 98ad1172b0
commit 67a2ca6e31
6 changed files with 118 additions and 8 deletions

View File

@@ -6,7 +6,8 @@ use aether_runtime::{ConcurrencyGate, DistributedConcurrencyGate};
use super::super::async_task::{VideoTaskPollerConfig, VideoTaskService};
use super::super::cache::{
AuthApiKeyLastUsedCache, AuthContextCache, DirectPlanBypassCache, SchedulerAffinityCache,
AuthApiKeyLastUsedCache, AuthContextCache, DashboardResponseCache, DirectPlanBypassCache,
SchedulerAffinityCache,
};
use super::super::data::GatewayDataState;
use super::super::fallback_metrics;
@@ -35,6 +36,7 @@ pub struct AppState {
pub(crate) oauth_refresh: Arc<provider_transport::LocalOAuthRefreshCoordinator>,
pub(crate) direct_plan_bypass_cache: Arc<DirectPlanBypassCache>,
pub(crate) scheduler_affinity_cache: Arc<SchedulerAffinityCache>,
pub(crate) dashboard_response_cache: Arc<DashboardResponseCache>,
pub(crate) fallback_metrics: Arc<fallback_metrics::GatewayFallbackMetrics>,
pub(crate) frontdoor_cors: Option<Arc<FrontdoorCorsConfig>>,
pub(crate) frontdoor_user_rpm: Arc<FrontdoorUserRpmLimiter>,

View File

@@ -22,8 +22,8 @@ use super::super::async_task::{
spawn_video_task_poller, VideoTaskPollerConfig, VideoTaskService, VideoTaskTruthSourceMode,
};
use super::super::cache::{
AuthApiKeyLastUsedCache, AuthContextCache, DirectPlanBypassCache, SchedulerAffinityCache,
SchedulerAffinitySnapshotEntry, SchedulerAffinityTarget,
AuthApiKeyLastUsedCache, AuthContextCache, DashboardResponseCache, DirectPlanBypassCache,
SchedulerAffinityCache, SchedulerAffinitySnapshotEntry, SchedulerAffinityTarget,
};
use super::super::data::{GatewayDataConfig, GatewayDataState};
use super::super::fallback_metrics;
@@ -144,6 +144,7 @@ impl AppState {
oauth_refresh: Arc::new(provider_transport::LocalOAuthRefreshCoordinator::new()),
direct_plan_bypass_cache: Arc::new(DirectPlanBypassCache::default()),
scheduler_affinity_cache: Arc::new(SchedulerAffinityCache::default()),
dashboard_response_cache: Arc::new(DashboardResponseCache::default()),
fallback_metrics: Arc::new(fallback_metrics::GatewayFallbackMetrics::default()),
frontdoor_cors: None,
frontdoor_user_rpm: Arc::new(FrontdoorUserRpmLimiter::new(