fix: 修复数据清理预览接口 panic 及路由文档路径翻倍问题
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m12s

1. CountOldRecords 改用 GORM .Scan() 替代 .Row().Scan(),避免查询不存在的表时 nil pointer panic
2. polling_cleanup 路由注册的 basePath 参数去掉多余拼接,修复生成的 OpenAPI 文档路径翻倍
This commit is contained in:
2026-03-30 15:09:14 +08:00
parent 06ee422e34
commit 33e7f99fdc
2 changed files with 7 additions and 10 deletions

View File

@@ -193,12 +193,11 @@ func (s *DataCleanupLogStore) CountOldRecords(ctx context.Context, tableName str
return 0, err
}
default:
// 对于其他表,使用原始 SQL
row := s.db.WithContext(ctx).Raw(
// 对于其他表,使用原始 SQL(使用 GORM 的 Scan 避免 Row() 返回 nil 导致 panic
if err := s.db.WithContext(ctx).Raw(
"SELECT COUNT(*) FROM "+tableName+" WHERE created_at < ?",
cutoffTime,
).Row()
if err := row.Scan(&count); err != nil {
).Scan(&count).Error; err != nil {
return 0, err
}
}