Skip to content

Conversation

@fancyboi999
Copy link

背景 & 目标

  • 现有历史记录从超大 JSON 读取,列表/查询会明显变慢
  • 目标:改为 SQLite 持久化,提升大数据量场景的读取性能与稳定性

主要改动

  • 新增 SQLAlchemy 模型 HistoryRecord,将历史记录存入 SQLite
  • 历史记录服务 HistoryService 全面改为 DB CRUD
  • 启动时自动创建表并补齐索引(status/created_at/task_id/复合索引)
  • 提供一次性迁移脚本 scripts/migrate_json_to_sqlite.py 兼容旧 JSON
  • SQLite 文件落在 history/redink.db(容器环境由 history 卷持久化)

解决的问题

  • 规避“超大 JSON 读取慢”的性能瓶颈
  • 历史记录查询/分页在数据增长后保持可用
  • 通过索引保证常用查询路径稳定

测试

  • 本地启动服务(uv run python -m backend.app)正常
  • 生成 history/redink.db 成功
  • 索引已创建(status/created_at/task_id/复合)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant