MCPcopy Create free account
hub / github.com/Quorinex/Kiro-Go / apiRefreshAccountModels

Method apiRefreshAccountModels

proxy/handler.go:644–674  ·  view source on GitHub ↗

apiRefreshAccountModels POST /admin/api/accounts/{id}/models/refresh 立即为指定账号拉取并更新模型路由缓存。

(w http.ResponseWriter, r *http.Request, id string)

Source from the content-addressed store, hash-verified

642 modelIDs := make([]string, 0, len(models))
643 for _, m := range models {
644 modelIDs = append(modelIDs, m.ModelId)
645 }
646 h.pool.SetModelList(account.ID, modelIDs)
647 aggregated = mergeUniqueModels(aggregated, models)
648 }
649
650 if len(aggregated) > 0 {
651 h.modelsCacheMu.Lock()
652 h.cachedModels = aggregated
653 h.modelsCacheTime = time.Now().Unix()
654 h.modelsCacheMu.Unlock()
655 logger.Infof("[ModelsCache] Cached %d models", len(aggregated))
656 }
657}
658
659// fetchAndCacheAccountModels 为单个账号拉取并写入模型缓存。
660// 同时更新 pool 的路由缓存与全局聚合模型列表。
661func (h *Handler) fetchAndCacheAccountModels(account *config.Account) error {
662 if err := h.ensureValidToken(account); err != nil {
663 return fmt.Errorf("token refresh failed: %w", err)
664 }
665 models, err := ListAvailableModels(account)
666 if err != nil {
667 return err
668 }
669 modelIDs := make([]string, 0, len(models))
670 for _, m := range models {
671 modelIDs = append(modelIDs, m.ModelId)
672 }
673 h.pool.SetModelList(account.ID, modelIDs)
674
675 // 合并到聚合缓存
676 h.modelsCacheMu.Lock()
677 h.cachedModels = mergeUniqueModels(h.cachedModels, models)

Callers 1

handleAdminAPIMethod · 0.95

Calls 5

GetAccountsFunction · 0.92
GetByIDMethod · 0.80
ErrorMethod · 0.80
GetModelListMethod · 0.80

Tested by

no test coverage detected