debug: 添加站点设置持久化调试日志,追踪 Set/Get 链路
Some checks failed
CI / Lint + Build (push) Has been cancelled

This commit is contained in:
2026-06-30 19:01:25 +08:00
parent 20067f7640
commit 1eb3cc7c86
2 changed files with 13 additions and 3 deletions

View File

@ -1,6 +1,7 @@
package config
import (
"log"
"strconv"
"sync"
@ -73,15 +74,19 @@ func (s *SiteSettings) GetBool(key string, defaultVal bool) bool {
// Set 写入设置(同步写 DB + 更新内存,使用 UPSERT 兼容首次保存)
func (s *SiteSettings) Set(key, value string) error {
entry := model.SiteSetting{Key: key, Value: value}
if err := s.db.Clauses(clause.OnConflict{
result := s.db.Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "key"}},
DoUpdates: clause.AssignmentColumns([]string{"value"}),
}).Create(&entry).Error; err != nil {
return err
}).Create(&entry)
if result.Error != nil {
log.Printf("[SiteSettings] Set FAIL key=%s value=%s err=%v", key, value, result.Error)
return result.Error
}
s.mu.Lock()
oldVal, existed := s.data[key]
s.data[key] = value
s.mu.Unlock()
log.Printf("[SiteSettings] Set OK key=%s old=%q new=%q existed=%v rows=%d", key, oldVal, value, existed, result.RowsAffected)
return nil
}

View File

@ -1,6 +1,7 @@
package admin
import (
"log"
"net/http"
"strconv"
@ -87,6 +88,10 @@ func (sc *SiteSettingController) ThemePage(c *gin.Context) {
func (sc *SiteSettingController) GetSettings(c *gin.Context) {
all := sc.settingService.GetSettings()
audit := sc.settingService.GetAuditSettings(sc.defaults)
log.Printf("[GetSettings] all=%d keys audit=%+v", len(all), audit)
if v, ok := all["registration.enabled"]; ok {
log.Printf("[GetSettings] registration.enabled=%q", v)
}
common.Ok(c, gin.H{
"all": all,
"audit": audit,