Skip to content

Enhance: 优化excel/csv导入性能#3885

Draft
onceMisery wants to merge 8 commits into
t8y2:mainfrom
onceMisery:feat/import-optimise
Draft

Enhance: 优化excel/csv导入性能#3885
onceMisery wants to merge 8 commits into
t8y2:mainfrom
onceMisery:feat/import-optimise

Conversation

@onceMisery

Copy link
Copy Markdown
Contributor

变更说明

  • CSV 改为有界通道流式解析,降低大文件导入时的内存占用
  • XLSX/XLSM 预览不再扫描实际总行数,提升大文件预览速度
  • XLSX worksheet 改为 XML 流式解析
  • 大型 shared strings 使用磁盘索引和受限缓存
  • PostgreSQL 导入增加 COPY 快速路径
  • Oracle 批量写入使用 INSERT ALL,并限制安全批次大小
  • SQL 根据语句大小自动拆批,避免超大语句
  • 增加导入耗时、阶段进度及性能指标日志

变更类型

  • 新功能
  • Bug 修复
  • 性能优化
  • 代码重构
  • 文档更新
  • CI / 构建

涉及前端

  • 本 PR 涉及前端改动,已附截图/录屏(见下方)
ce010114-bb21-4f4f-832b-0f6bdd9ef361

验证

  • make check 通过
  • make cargo-check-fast 通过
  • 相关测试通过

关联 Issue

#2999

其他

这个是导入的第1个PR,还有优化空间, 后续整理成第二个PR:

  • PostgreSQL COPY 改成按字节扩大批次
  • MySQL 增加按 SQL 字节数控制的自动批次
  • 行级 SQL 只序列化一次。

@t8y2 t8y2 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

当前审查被分支冲突阻塞,暂不作 approve/request-changes 结论。

精确 head e9432ca 与最新 main 在 16 个文件存在重叠冲突,包含本 PR 的核心调用链:crates/dbx-core/src/table_import.rsconnection.rstransfer.rs、Web import routes、前端 backend bridge 和全部 locale。当前 GitHub 状态为 CONFLICTING / DIRTY;现有绿灯 CI 验证的是冲突前的合成结果,不能证明冲突解决后的导入行为。

请先将最新 main 合入或重放到当前分支,保持改动范围聚焦,并重新运行 frontend、rust-fmt-clippy、rust-test 与数据库环境检查。更新 head 后我会继续检查 CSV/XLSX 流式解析、PostgreSQL COPY、Oracle INSERT ALL、取消语义和临时上传生命周期。

@t8y2 t8y2 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

request changes: 除当前与 main 的冲突外,XLSX 磁盘 shared-string 路径还存在一个独立的敏感数据暴露问题。

crates/dbx-core/src/table_import.rs:1655 在 shared strings 超过内存阈值后,将所有字符串值及其索引写入系统临时目录。两个文件都通过普通 OpenOptions::create_new(true) 创建,没有在 Unix 上指定 0o600,也没有使用安全临时文件实现。Rust 官方文档说明,未设置 mode 时新文件默认使用 0o666 再应用进程 umask;常见 0o022 下会得到 0o644,同机其他用户可读取导入中的客户数据、凭证或其他敏感表格内容。

官方文档:https://doc.rust-lang.org/std/os/unix/fs/trait.OpenOptionsExt.html

文件目前还只依赖 Drop 删除,进程崩溃或被强制结束时可能残留。

请使用安全临时文件实现(例如 Unix 默认 0o600 的 tempfile),或在 Unix 创建 data/index 文件时明确设置 mode(0o600);补强制磁盘路径测试,断言两个文件仅 owner 可读写,并覆盖正常结束、解析失败后的清理。完成后还需先解决当前 16 个重叠文件冲突并重跑完整 CI。

@onceMisery
onceMisery marked this pull request as draft July 20, 2026 14:50
@onceMisery
onceMisery marked this pull request as ready for review July 21, 2026 03:53
@onceMisery
onceMisery marked this pull request as draft July 21, 2026 03:57
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.

2 participants