Files
DanDingNoneBot/review_reports/danding_points_review.md
Mr.Xia c01338f496 refactor(plugins): comprehensive code review - ~35 fixes across 14 plugins
Phase 1 - Plugin code review (14/14 plugins):
- Security: 3x token leak in print→logger.debug, Bearer prefix handling
- Bug: bare except→specific exceptions, HorseState type safety, sync→async
- Critical: response_model undefined, route dead code, sync blocking event loop
- Quality: 11x print()→logger, variable name shadowing, consistent logging

Phase 2 - Deep analysis:
- Fix: payout int truncation→max(1, round(amount*odds))
- Fix: room_store get_lock race condition→dict.setdefault()
- Verify: data_manager f-string SQL is safe (uses ? placeholders)

Infrastructure: review reports generated for all plugins.
2026-05-09 23:22:28 +08:00

1.3 KiB
Raw Permalink Blame History

danding_points 评审报告

修复前问题清单 (3项)

# 严重度 问题 文件
1 except Exception 捕获后无日志记录、无rollback吞没错误导致调试困难 api.py:89,161,232
2 ensure_user_exists 在事务锁定区域内自行开新连接(conn=None),可能死锁或数据不一致 api.py + database.py
3 set_points 不更新 total_spent/total_earned,积分统计不准确 api.py

修复内容

api.py (303行)

  • 所有 except 块添加 logger.error() + conn.rollback() + except Exception as e
  • 添加 import logging + logger = logging.getLogger(__name__)
  • 调用 ensure_user_exists(user_id, conn) 传入已有连接

database.py (104行)

  • ensure_user_exists 签名改为 (self, user_id: str, conn=None)
  • 复用已有连接时不创建新连接、不commit/close无conn时自行创建并管理生命周期

验证结果 (9/9 ✓)

  • ✓ logging import & logger
  • ✓ 3x logger.error + 3x conn.rollback() + 3x except Exception as e
  • ✓ 调用方传conn、db定义接受conn
  • ✓ 无bare except
  • ✓ SQLite数据库无需HTTP timeout

代码质量总结

修复后评级:B (SQLite存储层设计合理错误处理已完善)