refactor(dashboard): remove unused web APIs and dead code - #2569
Conversation
Why this change was needed: These APIs were never called by the frontend and were cluttering the codebase. Removing dead code reduces cognitive overhead and makes the codebase easier to maintain and reason about. What changed: - Removed MCPServerUpdateLabelsApi and its serializer (mcp_server module) - Removed AlarmRecordSummaryListApi, its serializers, and MonitorHandler biz layer (monitor module) - Removed ReleaseHistoryRetrieveApi and its route (release module) - Commented out unused URL routes with FIXME markers for safe future removal - Deleted biz/monitor module (MonitorHandler class no longer needed) - Removed corresponding test files for deleted code Problem solved: Dead API endpoints and their supporting layers are no longer carried in the codebase. Future developers won't waste time understanding code that is never invoked. The FIXME comments allow a staged removal if any edge case surfaces.
wklken
left a comment
There was a problem hiding this comment.
Code Review
变更概述:移除未使用的 Web API 端点及相关死代码,包括 MCPServerUpdateLabelsApi、AlarmRecordSummaryListApi、ReleaseHistoryRetrieveApi、UserAuthTypeRetrieveApi,以及整个 biz/monitor 模块及其测试代码。部分 URL 路由通过注释方式标记待移除。
发现的问题
-
导入未清理 (
src/dashboard/apigateway/apigateway/tests/apis/web/release/test_views.py:32)create_gateway导入已不被使用(TestReleaseHistoryRetrieveApi测试类已移除),但导入语句未删除。- 建议:删除未使用的导入
from apigateway.tests.utils.testing import dummy_time(保留dummy_time检查正确) - 实际应删除:
create_gateway不再使用
-
变更不一致 (多个 url.py 文件)
- View 类和 Serializer 已完全删除,但 URL 路由仅注释未移除
- 已删除的 View 类:
MCPServerUpdateLabelsApi、ReleaseHistoryRetrieveApi、UserAuthTypeRetrieveApi、AlarmRecordSummaryListApi - 问题:如果 View 类已删除,对应的注释 URL 永远无法恢复功能,注释无意义
- 建议:将注释的 URL 一并删除,或在 URL 注释中注明 View 类已删除
-
无关变更 (
src/dashboard/AGENTS.md)- 增加 Git & Pull Request Workflow 文档与本次 PR 主题(移除死代码)无关
- 建议:文档变更应单独提交 PR,保持 PR 单一职责
优点
- 正确的代码删除:完整移除了不再使用的 View 类、Serializer、整个 business 模块及其测试
- 测试同步清理:对应的测试文件和测试类也被正确移除
- 变更范围清晰:删除的代码确实未被前端调用,属于真正的死代码清理
- 日期标记:注释带有 "2026-03-23" 日期标记,便于后续追溯
总结
该 PR 主要完成了死代码清理工作,移除了未被前端调用的 API 端点及相关代码。整体方向正确,清理较为彻底。
建议修复:删除测试文件中未使用的导入,移除指向已删除 View 类的 URL 注释,无关文档变更建议拆分。修复后可以合并。
由 Claude 自动 review | 基于默认 Review 规范 [from openclaw-internal]
wklken
left a comment
There was a problem hiding this comment.
Code Review
变更概述:本PR删除了4个未使用的Web API(MCPServerUpdateLabelsApi、AlarmRecordSummaryListApi、ReleaseHistoryRetrieveApi、UserAuthTypeRetrieveApi)及对应的序列化器、测试代码和biz/monitor模块,共减少557行代码。
发现的问题
-
URL处理策略不一致:大部分URL直接删除了import,但部分URL用FIXME注释的方式保留,这种混合策略可能导致未来维护时的困惑。
-
UserAuthTypeRetrieveApi未在描述中提及:PR描述只提到3个API,但实际还删除了UserAuthTypeRetrieveApi,应更新描述。 -
前端服务层存在僵尸代码:
src/dashboard-front/src/services/source/online-debugging.ts中的getUserAuthType函数已定义但未在代码中实际调用,建议一并清理前端代码。 -
AGENTS.md 修改与PR内容关联度低:AGENTS.md 的更新(Git工作流说明)与本次删除死代码的关联性较弱,可作为独立的文档提交。
优点
-
清理彻底:同时删除了 views、serializers、tests、biz层和URL配置,避免了孤立代码残留。
-
FIXME 注释提供时间追踪:注释中标注了注释日期(2026-03-23),便于追溯和后续清理。
-
测试覆盖完整:删除了所有相关的测试用例,确保测试与实现同步。
-
Commit message 规范:详细说明了变更原因、具体内容和解决的问题。
总结
这是一次良性的代码重构,减少代码维护负担。已删除的API经检查确实未被前端调用,MonitorHandler 也无其他引用,删除是安全的。建议合并,但建议后续统一处理前端僵尸代码和明确FIXME注释的清理计划。
由 Claude 自动 review | 基于默认 Review 流程 [from openclaw-internal]
Code Review 报告1. 基本信息
2. 问题统计
总计: 6 个问题 P1 问题清单:
3. 需求与设计符合性本次审查未关联具体需求文档,属于代码清理重构,跳过需求符合性分析。 重构目标:移除 4 个未被前端调用的 API 端点及其依赖代码。 4. 代码质量与复杂度分析4.1 变更概览
4.2 可读性评分
5. 深度代码审查5.1 严重问题 (Critical) 🛑✅ 未发现严重问题。 5.2 重要问题 (Major)
|
| 维度 | 得分 | 权重 | 说明 |
|---|---|---|---|
| 需求符合性 | N/A | 0% | 代码重构无外部需求 |
| 编程规范 | 7/10 | 30% | 缺少 CHANGELOG,FIXME 注释待改进 |
| 可读性 | 10/10 | 20% | 删除操作清晰 |
| 代码完整性 | 10/10 | 30% | 依赖链清理完整 |
| 安全性 | 10/10 | 20% | 无残留引用,数据模型完整 |
加权综合得分: 8.5 / 10
7.2 最终结论
✅ 建议合并(Approve with conditions)
理由:
- ✅ 代码完整性优秀:依赖链清理彻底,无残留引用
- ✅ 安全性优秀:数据模型正确保留,无风险操作
- ✅ 分阶段策略:URL 先注释而非直接删除,降低回滚成本
⚠️ 需补充:CHANGELOG + 改进 FIXME 注释 + 提供验证数据
合并条件(P1 问题):
- P1-1: 补充 CHANGELOG.md
- P1-2: 改进 FIXME 注释(明确观察期)
- P1-3: 提供 API 未使用的验证数据
合并后建议 (P2 问题):
- P2-1: 创建后续清理 issue (2026-04-23)
- P2-2: 通知前端团队
- P2-3: Staging 环境观察 1-2 周
附录:审查元数据
- 工具版本: CodeReview Skill v1.0
- 规则集: Python Coding Standards + Security Guidelines
- 语言统计:
- Python: 18 files, 571 lines changed
- 生成时间: 2026-03-23 20:46:00
A. 验证命令清单
# 1. 残留引用检查(已验证 ✅)
grep -r "from apigateway.biz.monitor import" --include="*.py" | grep -v test_
grep -r "MonitorHandler" --include="*.py" | grep -v test_
# 2. 项目启动检查
python manage.py check
# 3. 单元测试
pytest apigateway/tests/apis/web/monitor/ -v
pytest apigateway/tests/apis/web/mcp_server/ -v
pytest apigateway/tests/apis/web/release/ -vB. 参考资料
- Python Best Practices: Error Handling & Resource Management
- Django REST Framework: API Deprecation Strategy
Reviewed by OpenClaw Code Review Skill
[from openclaw-internal]
…eKing#2569) * refactor(dashboard): remove unused web APIs and dead code Why this change was needed: These APIs were never called by the frontend and were cluttering the codebase. Removing dead code reduces cognitive overhead and makes the codebase easier to maintain and reason about. What changed: - Removed MCPServerUpdateLabelsApi and its serializer (mcp_server module) - Removed AlarmRecordSummaryListApi, its serializers, and MonitorHandler biz layer (monitor module) - Removed ReleaseHistoryRetrieveApi and its route (release module) - Commented out unused URL routes with FIXME markers for safe future removal - Deleted biz/monitor module (MonitorHandler class no longer needed) - Removed corresponding test files for deleted code Problem solved: Dead API endpoints and their supporting layers are no longer carried in the codebase. Future developers won't waste time understanding code that is never invoked. The FIXME comments allow a staged removal if any edge case surfaces. * docs(agents.md): add the wrong PR guide * feat(agents.md): update
Summary
What changed
Made with Cursor