# MemALL 代码审查总结 — 速查卡

来源分析任务: e:/MemALL (67+ turns, ~9200行Python源码)  
日期: 2026-06-07  

## CRITICAL 缺陷 (5项)

| ID | 问题 | 文件位置 | 影响 |
|----|------|---------|------|
| S01 | UPDATE查询含SQL拼接风险 | thin_waist.py L104-111 | FTS搜索 + trust_filter中WHERE子句可能参数化不足 |
| S02 | LAN通信无任何加密/认证 | gateway.py 全链路 | Discovery伪造、MITM劫持peer列表、Query嗅探 |
| S03 | CORS过度宽松 | gateway.py L65 | "http://localhost:*" → 若绑定0.0.0.0即公共暴露面 |
| S04 | ConnectionPool写死未使用 | db.py(池定义vs thin_waist直连) | ~20处get_conn()应替换为pool.connection()上下文管理器 |
| S05 | Embedding计算后不持久化 | smart_store() → tfidf_svd_embed()结果仅内存用 | vector_search/hybrid永远退化为keyword LIKE匹配 |

## HIGH priority (3项)

| ID | 问题 | 预估工时 |
|----|------|---------|
| H01 | pipeline link/cluster Jaccard O(n^2), 大数据慢数十分钟 | MinHash/LSH降维O(n) |
| H02 | Migration引擎无法处理类型变更/RECREATE | 升级到版本比较器(v2) |
| H03 | GraphEmbedding无numpy守卫, 缺依赖直接崩溃 | try/except ImportError |

## DEV QUALITY (3项)

| ID | 问题 |
|----|------|
| D01 | update/capture/retrieve三条CRUD核心路径完全缺失单元测试 |
| D02 | gateway.py重复实现两套federated_retrieve(sync+async) |
| D03 | management_commands.py 700行超规范上限(~300行/file) |

## Security Hardening Priority List (6 items)

```
┌───────┐  ─S1 4h→ ┌──────────────────────┐
│ Auth  │          │ API Key authentication │
└───────┘  ─S4 <1h->│  Authorization header│  
                  └──────────────────────┘
┌───────┐
│ CORS  │    ← 先改这个最快见效(S4: 1h) ──> restricted origin list
└───────┘
              └─S6 8h─> SQLite全面参数化Code Audit
```

## Performance Targets (from DELIVERY_REPORT Phase-20 suggestion)

```
Data   │ Single Capture │ Pipeline Full   │ Vector Search
Size   │ Latency        │ Execution Time  │ Response Time
───────┼────────────────┼─────────────────┼──────────────
  1K   │     < 5ms      │     < 2s        │   < 200ms
 10K   │     < 5ms      │     < 8s        │   < 500ms
100K   │     < 5ms      │     < 30s       │   < 1000ms
```

Implementation approach: data gen script → baseline benchmark → implement fixes → re-benchmark → document delta
