feat: update system config cache for AppServer when updating system config in admin console

This commit is contained in:
RockYang
2023-07-31 08:13:20 +08:00
parent 29094ba3b3
commit bed184dc1f
3 changed files with 17 additions and 15 deletions

View File

@@ -48,6 +48,16 @@ func (h *ConfigHandler) Update(c *gin.Context) {
resp.ERROR(c, res.Error.Error())
return
}
// update config cache for AppServer
var cfg model.Config
h.db.Where("marker", data.Key).First(&cfg)
err := utils.JsonDecode(cfg.Config, &h.App.ChatConfig)
if err != nil {
resp.ERROR(c, "Failed to update config cache: "+err.Error())
return
}
logger.Infof("Update AppServer's config successfully: %v", config.Config)
}
resp.SUCCESS(c, config)

View File

@@ -108,16 +108,7 @@ func (h *UserHandler) Register(c *gin.Context) {
Model: h.App.ChatConfig.Model,
ApiKey: "",
}),
}
// 初始化调用次数
var cfg model.Config
h.db.Where("marker = ?", "system").First(&cfg)
var config types.SystemConfig
err := utils.JsonDecode(cfg.Config, &config)
if err != nil || config.UserInitCalls <= 0 {
user.Calls = types.UserInitCalls
} else {
user.Calls = config.UserInitCalls
Calls: h.App.SysConfig.UserInitCalls,
}
res = h.db.Create(&user)
if res.Error != nil {