@@ -410,6 +410,7 @@ type accountResponse struct {
410410 ProxyURL string `json:"proxy_url"`
411411 CreatedAt string `json:"created_at"`
412412 UpdatedAt string `json:"updated_at"`
413+ CodexUsageUpdatedAt string `json:"codex_usage_updated_at,omitempty"`
413414 ActiveRequests int64 `json:"active_requests"`
414415 TotalRequests int64 `json:"total_requests"`
415416 LastUsedAt string `json:"last_used_at"`
@@ -517,8 +518,8 @@ func (h *Handler) ListAccounts(c *gin.Context) {
517518 Status : row .Status ,
518519 ErrorMessage : row .ErrorMessage ,
519520 ATOnly : ! isOpenAIResponsesAccount && row .GetCredential ("refresh_token" ) == "" && row .GetCredential ("access_token" ) != "" ,
520- CreditEnabled : row .CreditEnabled ,
521- CreditSkipUsageWindow : row .CreditSkipUsageWindow ,
521+ CreditEnabled : row .CreditEnabled ,
522+ CreditSkipUsageWindow : row .CreditSkipUsageWindow ,
522523 AccountType : row .Type ,
523524 OpenAIResponsesAPI : isOpenAIResponsesAccount ,
524525 BaseURL : baseURL ,
@@ -534,6 +535,7 @@ func (h *Handler) ListAccounts(c *gin.Context) {
534535 BaseConcurrencyEffective : effectiveBaseConcurrency (row .BaseConcurrencyOverride , int64 (h .store .GetMaxConcurrency ())),
535536 CreatedAt : row .CreatedAt .Format (time .RFC3339 ),
536537 UpdatedAt : row .UpdatedAt .Format (time .RFC3339 ),
538+ CodexUsageUpdatedAt : row .GetCredential ("codex_usage_updated_at" ),
537539 }
538540 if acc , ok := accountMap [row .ID ]; ok {
539541 acc .Mu ().RLock ()
@@ -1191,16 +1193,18 @@ func (h *Handler) AddAccount(c *gin.Context) {
11911193 }
11921194 h .store .AddAccount (newAcc )
11931195
1194- // 异步刷新 AT
1195- go func (accountID int64 ) {
1196- refreshCtx , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
1197- defer cancel ()
1198- if err := h .store .RefreshSingle (refreshCtx , accountID ); err != nil {
1199- log .Printf ("新账号 %d 刷新失败: %v" , accountID , err )
1200- } else {
1201- log .Printf ("新账号 %d 刷新成功,已加入号池" , accountID )
1202- }
1203- }(id )
1196+ if ! h .store .GetLazyMode () {
1197+ // 异步刷新 AT
1198+ go func (accountID int64 ) {
1199+ refreshCtx , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
1200+ defer cancel ()
1201+ if err := h .store .RefreshSingle (refreshCtx , accountID ); err != nil {
1202+ log .Printf ("新账号 %d 刷新失败: %v" , accountID , err )
1203+ } else {
1204+ log .Printf ("新账号 %d 刷新成功,已加入号池" , accountID )
1205+ }
1206+ }(id )
1207+ }
12041208 }
12051209
12061210 // 记录安全审计日志
@@ -2300,7 +2304,7 @@ func (h *Handler) importAccountsCommon(c *gin.Context, tokens []importToken, pro
23002304 newAcc := accountFromCredentialSeed (id , proxyURL , seed )
23012305 h .store .AddAccount (newAcc )
23022306
2303- if tok .accessToken == "" {
2307+ if tok .accessToken == "" && ! h . store . GetLazyMode () {
23042308 // 后台异步刷新,不阻塞导入流程
23052309 go func (accountID int64 ) {
23062310 refreshCtx , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
@@ -3561,6 +3565,7 @@ type settingsResponse struct {
35613565 BackgroundRefreshIntervalMinutes int `json:"background_refresh_interval_minutes"`
35623566 UsageProbeMaxAgeMinutes int `json:"usage_probe_max_age_minutes"`
35633567 RecoveryProbeIntervalMinutes int `json:"recovery_probe_interval_minutes"`
3568+ LazyMode bool `json:"lazy_mode"`
35643569 ProxyURL string `json:"proxy_url"`
35653570 PgMaxConns int `json:"pg_max_conns"`
35663571 RedisPoolSize int `json:"redis_pool_size"`
@@ -3621,6 +3626,7 @@ type updateSettingsReq struct {
36213626 BackgroundRefreshIntervalMinutes * int `json:"background_refresh_interval_minutes"`
36223627 UsageProbeMaxAgeMinutes * int `json:"usage_probe_max_age_minutes"`
36233628 RecoveryProbeIntervalMinutes * int `json:"recovery_probe_interval_minutes"`
3629+ LazyMode * bool `json:"lazy_mode"`
36243630 ProxyURL * string `json:"proxy_url"`
36253631 PgMaxConns * int `json:"pg_max_conns"`
36263632 RedisPoolSize * int `json:"redis_pool_size"`
@@ -3761,6 +3767,7 @@ func (h *Handler) GetSettings(c *gin.Context) {
37613767 BackgroundRefreshIntervalMinutes : h .store .GetBackgroundRefreshIntervalMinutes (),
37623768 UsageProbeMaxAgeMinutes : h .store .GetUsageProbeMaxAgeMinutes (),
37633769 RecoveryProbeIntervalMinutes : h .store .GetRecoveryProbeIntervalMinutes (),
3770+ LazyMode : h .store .GetLazyMode (),
37643771 ProxyURL : h .store .GetProxyURL (),
37653772 PgMaxConns : h .pgMaxConns ,
37663773 RedisPoolSize : h .redisPoolSize ,
@@ -3773,7 +3780,7 @@ func (h *Handler) GetSettings(c *gin.Context) {
37733780 AutoCleanExpired : h .store .GetAutoCleanExpired (),
37743781 ProxyPoolEnabled : h .store .GetProxyPoolEnabled (),
37753782 FastSchedulerEnabled : h .store .FastSchedulerEnabled (),
3776- SchedulerMode : h .store .GetSchedulerMode (),
3783+ SchedulerMode : h .store .GetSchedulerMode (),
37773784 MaxRetries : h .store .GetMaxRetries (),
37783785 MaxRateLimitRetries : h .store .GetMaxRateLimitRetries (),
37793786 AllowRemoteMigration : h .store .GetAllowRemoteMigration () && adminAuthSource != "disabled" ,
@@ -3929,6 +3936,11 @@ func (h *Handler) UpdateSettings(c *gin.Context) {
39293936 log .Printf ("设置已更新: recovery_probe_interval_minutes = %d" , v )
39303937 }
39313938
3939+ if req .LazyMode != nil {
3940+ h .store .SetLazyMode (* req .LazyMode )
3941+ log .Printf ("设置已更新: lazy_mode = %t" , * req .LazyMode )
3942+ }
3943+
39323944 if req .ProxyURL != nil {
39333945 h .store .SetProxyURL (* req .ProxyURL )
39343946 log .Printf ("设置已更新: proxy_url = %s" , * req .ProxyURL )
@@ -4241,6 +4253,7 @@ func (h *Handler) UpdateSettings(c *gin.Context) {
42414253 BackgroundRefreshIntervalMinutes : h .store .GetBackgroundRefreshIntervalMinutes (),
42424254 UsageProbeMaxAgeMinutes : h .store .GetUsageProbeMaxAgeMinutes (),
42434255 RecoveryProbeIntervalMinutes : h .store .GetRecoveryProbeIntervalMinutes (),
4256+ LazyMode : h .store .GetLazyMode (),
42444257 ProxyURL : h .store .GetProxyURL (),
42454258 PgMaxConns : h .pgMaxConns ,
42464259 RedisPoolSize : h .redisPoolSize ,
@@ -4252,7 +4265,7 @@ func (h *Handler) UpdateSettings(c *gin.Context) {
42524265 AutoCleanExpired : h .store .GetAutoCleanExpired (),
42534266 ProxyPoolEnabled : h .store .GetProxyPoolEnabled (),
42544267 FastSchedulerEnabled : h .store .FastSchedulerEnabled (),
4255- SchedulerMode : h .store .GetSchedulerMode (),
4268+ SchedulerMode : h .store .GetSchedulerMode (),
42564269 MaxRetries : h .store .GetMaxRetries (),
42574270 MaxRateLimitRetries : h .store .GetMaxRateLimitRetries (),
42584271 AllowRemoteMigration : h .store .GetAllowRemoteMigration () && hasAdminSecret ,
@@ -4304,6 +4317,7 @@ func (h *Handler) UpdateSettings(c *gin.Context) {
43044317 BackgroundRefreshIntervalMinutes : h .store .GetBackgroundRefreshIntervalMinutes (),
43054318 UsageProbeMaxAgeMinutes : h .store .GetUsageProbeMaxAgeMinutes (),
43064319 RecoveryProbeIntervalMinutes : h .store .GetRecoveryProbeIntervalMinutes (),
4320+ LazyMode : h .store .GetLazyMode (),
43074321 ProxyURL : h .store .GetProxyURL (),
43084322 PgMaxConns : h .pgMaxConns ,
43094323 RedisPoolSize : h .redisPoolSize ,
@@ -4316,7 +4330,7 @@ func (h *Handler) UpdateSettings(c *gin.Context) {
43164330 AutoCleanExpired : h .store .GetAutoCleanExpired (),
43174331 ProxyPoolEnabled : h .store .GetProxyPoolEnabled (),
43184332 FastSchedulerEnabled : h .store .FastSchedulerEnabled (),
4319- SchedulerMode : h .store .GetSchedulerMode (),
4333+ SchedulerMode : h .store .GetSchedulerMode (),
43204334 MaxRetries : h .store .GetMaxRetries (),
43214335 MaxRateLimitRetries : h .store .GetMaxRateLimitRetries (),
43224336 AllowRemoteMigration : h .store .GetAllowRemoteMigration () && adminAuthSource != "disabled" ,
0 commit comments