-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix: 修复删除交易员后排行榜仍显示已删除交易员的问题 #622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
## Problem After deleting a trader, the leaderboard and navigation selector don't update immediately: - AITradersPage updates instantly (has mutateTraders) - CompetitionPage waits 15s (different SWR key) - App.tsx navigation waits 10s (isolated cache) ## Solution Create unified cache manager (lib/cache.ts): - Define cross-page data dependencies - Provide semantic cache invalidation methods - Auto-sync all related pages ## Changes - Add web/src/lib/cache.ts - Unified cache management - Update web/src/components/AITradersPage.tsx - Use cacheManager ## Related - Complements backend fix in PR NoFxAiOS#622 - Frontend layer: instant UI updates - Backend layer: correct data source 🤖 Generated with Claude Code Co-Authored-By: Claude <[email protected]>
## Problem After deleting a trader, the competition API still returns the deleted trader because: - Database deletion succeeds - But TraderManager.traders map still contains the trader - GetCompetitionData() iterates over tm.traders map (includes deleted ones) ## Solution Add RemoveTrader() method to TraderManager: - Stop the trader if running - Remove from traders map - Simplified version (no competitionCache, z-dev doesn't have it) ## Changes - Add manager/trader_manager.go::RemoveTrader() - Update api/server.go::handleDeleteTrader() to call RemoveTrader() ## Comparison with PR NoFxAiOS#622 - PR NoFxAiOS#622: Full version with competitionCache clearing - Ours: Simplified for z-dev (no competitionCache yet) - Both solve the same core problem - Ours is compatible with current z-dev architecture ## Related - Inspired by PR NoFxAiOS#622 @songzhihui - Complements frontend fix (commit 685f248) - Frontend: instant UI updates - Backend: correct data source 🤖 Generated with Claude Code Co-Authored-By: Claude <[email protected]>
🤖 Advisory Check ResultsThese are advisory checks to help improve code quality. They won't block your PR from being merged. 📋 PR InformationTitle Format: ✅ Good - Follows Conventional Commits 🔧 Backend ChecksGo Formatting: Files needing formattingGo Vet: ✅ Good Fix locally: go fmt ./... # Format code
go vet ./... # Check for issues
go test ./... # Run tests⚛️ Frontend ChecksBuild & Type Check: ✅ Success Fix locally: cd web
npm run build # Test build (includes type checking)📖 ResourcesQuestions? Feel free to ask in the comments! 🙏 These checks are advisory and won't block your PR from being merged. This comment is automatically generated from pr-checks-run.yml. |
代码审查报告 - PR #622✅ 审查结果: 通过📋 基本信息
🎯 问题与解决方案问题: 删除trader后排行榜仍显示已删除trader(缓存未清理) ✅ 评估
🔧 建议
审查者: Claude AI Code Reviewer |
代码审查报告 - PR #622 (完整详细版)📋 基本信息
1️⃣ 业务逻辑审查✅ 问题定义核心Bug: 删除trader后,排行榜仍然显示已删除的trader 问题根源: 实际影响: ✅ 解决方案验证修复策略: 内存和数据库双向同步删除 业务逻辑正确性: ✅ 完全解决问题
2️⃣ 技术实现审查✅ 核心修改1: 新增RemoveTrader方法// manager/trader_manager.go:428
func (tm *TraderManager) RemoveTrader(traderID string) error {
tm.mu.Lock()
defer tm.mu.Unlock()
// 1. 检查trader是否存在
trader, exists := tm.traders[traderID]
if !exists {
return fmt.Errorf("交易员不存在: %s", traderID)
}
// 2. 停止运行中的trader
status := trader.GetStatus()
if isRunning, ok := status["is_running"].(bool); ok && isRunning {
trader.Stop()
log.Printf("⏹ 已停止运行中的交易员: %s", traderID)
}
// 3. 从map中删除
delete(tm.traders, traderID)
log.Printf("✓ 已从管理器中移除交易员: %s", traderID)
// 4. 清空竞赛数据缓存
tm.competitionCache.mu.Lock()
tm.competitionCache.data = make(map[string]interface{})
tm.competitionCache.timestamp = time.Time{}
tm.competitionCache.mu.Unlock()
log.Printf("🗑️ 已清空竞赛数据缓存")
return nil
}技术亮点:
评价: ✅ 实现正确,逻辑清晰
|
| 维度 | 评分 | 说明 |
|---|---|---|
| 业务逻辑 | ⭐⭐⭐⭐⭐ | 完全解决排行榜显示"幽灵trader"问题 |
| 技术实现 | ⭐⭐⭐⭐ | 逻辑正确,但缓存清空过于激进 |
| 并发安全 | ⭐⭐⭐⭐⭐ | 使用锁保护,无并发问题 |
| 代码质量 | ⭐⭐⭐⭐ | 封装良好,建议添加测试 |
🎯 核心价值
- 数据一致性: 数据库和内存双向同步删除
- 用户体验: 删除后排行榜立即更新(无需重启)
- 资源管理: 优雅停止trader,释放goroutine
🔧 行动建议
必须修复: 无
强烈建议:
- 优化缓存失效策略(只失效而非清空,或细粒度删除)
- 添加单元测试验证RemoveTrader逻辑
可选优化:
- 添加事务处理(先删内存,失败可回滚)
- 添加Prometheus指标监控trader删除频率
- 考虑软删除(标记为deleted而非物理删除)
🌟 特别表扬
问题定位: 准确识别内存和数据库不一致的根本原因
解决方案: 完整覆盖数据库、内存、缓存三个层面
代码封装: RemoveTrader方法设计合理,逻辑清晰
附加功能: LoadUserTraders支持热重载(优秀的附加价值)
总评: 这是一个高质量的Bug修复,彻底解决排行榜数据不一致问题。代码实现正确、线程安全、资源管理到位。缓存清空策略可以优化,但当前实现简单有效。建议合并后添加单元测试,并考虑优化缓存策略以提升性能。
审查时间: 2025-11-08
审查者: Claude AI Code Reviewer
问题原因:
修复方案: