🚀 refactor: refine pricing refresh logic & hide disabled models

Summary
-------
1. Pricing generation
   • `model/pricing.go`: skip any model whose `status != 1` when building
     `pricingMap`, ensuring disabled models are never returned to the
     front-end.

2. Cache refresh placement
   • `controller/model_meta.go`
     – Removed `model.RefreshPricing()` from pure read handlers
       (`GetAllModelsMeta`, `SearchModelsMeta`).
     – Kept refresh only in mutating handlers
       (`Create`, `Update`, `Delete`), guaranteeing data is updated
       immediately after an admin change while avoiding redundant work
       on every read.

Result
------
Front-end no longer receives information about disabled models, and
pricing cache refreshes occur exactly when model data is modified,
improving efficiency and consistency.
This commit is contained in:
t0ng7u
2025-08-05 23:18:12 +08:00
parent d951485431
commit 327a0ca323
3 changed files with 20 additions and 16 deletions

View File

@@ -13,8 +13,6 @@ import (
// GetAllModelsMeta 获取模型列表(分页)
func GetAllModelsMeta(c *gin.Context) {
model.RefreshPricing()
pageInfo := common.GetPageQuery(c)
modelsMeta, err := model.GetAllModels(pageInfo.GetStartIdx(), pageInfo.GetPageSize())
if err != nil {
@@ -35,8 +33,6 @@ func GetAllModelsMeta(c *gin.Context) {
// SearchModelsMeta 搜索模型列表
func SearchModelsMeta(c *gin.Context) {
model.RefreshPricing()
keyword := c.Query("keyword")
vendor := c.Query("vendor")
pageInfo := common.GetPageQuery(c)
@@ -87,6 +83,7 @@ func CreateModelMeta(c *gin.Context) {
common.ApiError(c, err)
return
}
model.RefreshPricing()
common.ApiSuccess(c, &m)
}
@@ -116,6 +113,7 @@ func UpdateModelMeta(c *gin.Context) {
return
}
}
model.RefreshPricing()
common.ApiSuccess(c, &m)
}
@@ -131,6 +129,7 @@ func DeleteModelMeta(c *gin.Context) {
common.ApiError(c, err)
return
}
model.RefreshPricing()
common.ApiSuccess(c, nil)
}
@@ -149,5 +148,4 @@ func fillModelExtra(m *model.Model) {
m.EnableGroups = model.GetModelEnableGroups(m.ModelName)
// 填充计费类型
m.QuotaType = model.GetModelQuotaType(m.ModelName)
}