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:
@@ -56,6 +56,7 @@ func (h *bufferHub) append(entry Entry) Entry {
|
||||
h.nextEntryID++
|
||||
entry.ID = h.nextEntryID
|
||||
if len(h.entries) >= h.limit {
|
||||
h.entries[0] = Entry{} // 释放旧条目引用,允许 GC 回收
|
||||
h.entries = append(h.entries[1:], entry)
|
||||
} else {
|
||||
h.entries = append(h.entries, entry)
|
||||
|
||||
Reference in New Issue
Block a user