mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-09-17 16:56:38 +08:00
feat: update system config cache for AppServer when updating system config in admin console
This commit is contained in:
parent
fad78641d6
commit
e7ac26ff5a
@ -74,21 +74,22 @@ func (s *AppServer) Init(debug bool) {
|
|||||||
|
|
||||||
func (s *AppServer) Run(db *gorm.DB) error {
|
func (s *AppServer) Run(db *gorm.DB) error {
|
||||||
// load chat config from database
|
// load chat config from database
|
||||||
var config model.Config
|
var chatConfig model.Config
|
||||||
res := db.Where("marker", "chat").First(&config)
|
res := db.Where("marker", "chat").First(&chatConfig)
|
||||||
if res.Error != nil {
|
if res.Error != nil {
|
||||||
return res.Error
|
return res.Error
|
||||||
}
|
}
|
||||||
err := utils.JsonDecode(config.Config, &s.ChatConfig)
|
err := utils.JsonDecode(chatConfig.Config, &s.ChatConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// load system configs
|
// load system configs
|
||||||
res = db.Where("marker", "system").First(&config)
|
var sysConfig model.Config
|
||||||
|
res = db.Where("marker", "system").First(&sysConfig)
|
||||||
if res.Error != nil {
|
if res.Error != nil {
|
||||||
return res.Error
|
return res.Error
|
||||||
}
|
}
|
||||||
err = utils.JsonDecode(config.Config, &s.SysConfig)
|
err = utils.JsonDecode(sysConfig.Config, &s.SysConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,16 @@ func (h *ConfigHandler) Update(c *gin.Context) {
|
|||||||
resp.ERROR(c, res.Error.Error())
|
resp.ERROR(c, res.Error.Error())
|
||||||
return
|
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)
|
resp.SUCCESS(c, config)
|
||||||
|
@ -108,16 +108,7 @@ func (h *UserHandler) Register(c *gin.Context) {
|
|||||||
Model: h.App.ChatConfig.Model,
|
Model: h.App.ChatConfig.Model,
|
||||||
ApiKey: "",
|
ApiKey: "",
|
||||||
}),
|
}),
|
||||||
}
|
Calls: h.App.SysConfig.UserInitCalls,
|
||||||
// 初始化调用次数
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
res = h.db.Create(&user)
|
res = h.db.Create(&user)
|
||||||
if res.Error != nil {
|
if res.Error != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user