docs: Add File Scan System documentation

Added complete documentation for scan/hash commands:
- CLI commands usage
- Performance test results (11857 files in 0.89s import)
- Design decisions (UUID strategy, path storage)
- Async hash system architecture
- Database structure examples
- Usage workflows

Performance highlights:
- Fast import: 14243 nodes/sec
- Async hash: 28 files/sec (4 threads)
- Total: 12658 nodes (warren user)

Version: 1.7 (File Scan System)
This commit is contained in:
Warren
2026-05-17 03:21:25 +08:00
parent 05f89ea1ac
commit 6b11e8fa41

128
AGENTS.md
View File

@@ -1052,3 +1052,131 @@ curl http://localhost:11438/api/v2/config/validate
**最后更新:** 2026-05-16 20:35
**版本:** 1.6UI Settings系统版
---
## File Scan System2026-05-17新增
### 功能概述
**异步导入系统:**
- 快速导入skip_hash=true立即显示文件树
- 后台hash异步计算SHA256不影响前端使用
### CLI命令
**scan命令**
```bash
# 快速导入默认skip_hash=true
cargo run -- scan --user warren --dir /Users/accusys/momentry/var/sftpgo/data/warren
# 导入并计算hashskip_hash=false
cargo run -- scan --user warren --dir <path> --skip-hash false --threads 4
# 参数说明:
--user <USER> 用户ID
--dir <DIR> 扫描目录
--batch <BATCH> 批量插入大小默认100
--skip-hash <BOOL> 跳过hash计算默认true
--threads <THREADS> hash计算线程数默认4
````
**hash命令**
```bash
# 后台计算hash
cargo run -- hash --user warren --threads 4
# 参数说明:
--user <USER> 用户ID
--threads <THREADS> 并行线程数默认4
````
### 效能测试结果2026-05-17
**测试配置:**
- 文件总数11857 files + 801 folders = 12658 nodes
- 目录深度多层子目录Accusys/Accusys_FAE/VolPack_ME5012...
- CPU线程4 threads (M4 Mac mini)
**第一阶段快速导入skip_hash=true**
- 目录扫描0.10s
- ID生成0.57s(主要瓶颈)
- 数据库插入0.21s
- 总时间0.89s
- 速度14243 nodes/sec
**第二阶段SHA256计算4 threads**
- 文件数11857
- 总时间417.58s
- 速度28 files/sec
**效能瓶颈分析:**
1. ID生成64%- SHA256计算UUID耗时
2. 数据库插入24%- 批量插入优化
3. 目录扫描11%- fast, no bottleneck
4. Hash计算 - IO瓶颈多线程未提速
### 设计决策
**UUID生成策略**
- 算法SHA256(path|filename|mac|mtime).chars().take(32)
- 特性确定性UUID同一文件 = 同一UUID
- 优势无需外部API支持增量导入
**路径存储方案:**
- 存储位置aliases.json临时方案
- 格式:`{"path": "/full/path/to/file"}`
- 原因file_nodes表无path字段
- 改进未来添加file_locations表填充
**异步hash设计**
- 导入优先:用户立即查看文件树
- hash后台不影响前端使用
- 多线程并行计算IO瓶颈限制
- 增量只计算缺失hash的文件
### 数据库结构warren.sqlite
**节点统计:**
- Folders: 801
- Files: 11857
- Total: 12658
**示例节点:**
```
node_id: 8b1ede3cd6970f02fa85b8e34b682caf
label: Test_Plan_ME5.docx
aliases_json: {"path":"/Users/accusys/.../Test_Plan_ME5.docx"}
sha256: 355a063b697a812742fae2a021cdda5c
node_type: file
parent_id: (folder UUID)
````
### 使用流程
**完整导入流程:**
```
1. cargo run -- scan --user warren --dir <path> # 快速导入0.89s
2. cargo run -- hash --user warren --threads 4 # 后台hash417s
3. 查看文件树http://localhost:11438/ → File Tree → Login
````
**增量导入流程:**
```
1. cargo run -- scan --user warren --dir <path> # 导入新文件
2. cargo run -- hash --user warren # 计算新hash只计算缺失的
````
### 相关文件
|文件 |功能 |
|------|------|
| src/scan.rs | 扫描导入 + hash计算499行|
| src/main.rs | CLI命令定义scan/hash|
| src/filetree/mod.rs | FileTree::init_user_db |
| data/users/warren.sqlite | warren用户数据库12658 nodes|
---
**最后更新:** 2026-05-17 02:15
**版本:** 1.7File Scan System版