refactor: 后端代码优化 11 项(codestable/refactors/2026-04-25-backend-cleanup)
- 提取 getWKFromContext 辅助函数,消除 handler 中 5 处重复代码 - 提取 retryCode 函数,消除 Login/performStudy 中验证码重试重复 - 提取 removeSession 内部方法,消除 Del/ClearAll/ClearExpired 中 3 处重复 - 提取 WK.UserKey() 方法,消除 4 处 userKey 手动拼接 - SessionManager.Get() 改用 RLock 优化读性能 - GetRecords 递归分页改为迭代,避免栈溢出 - prepareRequestClient 添加配置缓存,仅在 debug 设置变化时重建 - 修正 schedule.go 时区为 Asia/Shanghai + cron "0 6 * * *" - 修正 typo "以达到" → "已达到" - 删除未使用的 QAList struct - 修复 bufferHub.append 切片内存泄漏 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -11,14 +11,14 @@ import (
|
||||
)
|
||||
|
||||
func StartCron(m *ckwk.SessionManager) {
|
||||
loc, _ := time.LoadLocation("Asia/Singapore")
|
||||
loc, _ := time.LoadLocation("Asia/Shanghai")
|
||||
|
||||
c := cron.New(
|
||||
cron.WithLocation(loc),
|
||||
)
|
||||
|
||||
// 每天 6 点执行
|
||||
_, err := c.AddFunc("0 2 * * *", func() {
|
||||
_, err := c.AddFunc("0 6 * * *", func() {
|
||||
log.Info("开始定时清理 Session")
|
||||
m.ClearAll()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user