S146-M1: Nuxt Registries Investigation — CHỈ ĐIỀU TRA
Date: 2026-03-29 | OR: v7.4 | CHỈ BÁO CÁO. KHÔNG SỬA CODE.
Bảng 1: Dòng ảo Nuxt tự tạo
| Dòng UI |
Code |
File:Line |
Logic tạo |
Có trong Directus? |
| KHÔNG CÓ |
— |
— |
— |
— |
Kết luận: Grep toàn bộ web/ cho CAT-ORP, CAT-PHA, CAT-SPE, CAT-UNM, phantom, unmapped = 0 kết quả. Nuxt KHÔNG tạo dòng ảo. Nếu user thấy dòng lạ → do data trong v_registry_counts table (PG, không phải view) hoặc meta_catalog.
Bảng 2: Logic vi phạm §0-BA
| File |
Line |
Code snippet |
Loại |
Đánh giá |
| index.vue |
80-114 |
Changelog grouping by minute |
Data transform |
HỢP LÝ — UI cần hiện timeline |
| index.vue |
159-196 |
v_registry_counts → crosscheck map |
Data display |
HỢP LÝ — đọc từ PG table, render |
| [entityType]/index.vue |
47-63 |
Fetch ALL changelog (limit:-1) + count created/deleted |
Client-side aggregation |
NÊN CHUYỂN sang PG aggregate |
| [entityType]/index.vue |
72-86 |
crosscheckResult: nguoc = baseline + created - deleted |
Client calculation |
NÊN CHUYỂN sang PG view |
| all/index.vue |
97-103 |
N+1: fetch each collection with limit:-1 |
Performance |
CẦN FIX — sẽ chậm khi scale |
Kết luận: Không có vi phạm §0-BA nghiêm trọng. Logic hiện tại là data transformation cho display (hợp lý). 2 chỗ nên optimize (changelog aggregation + N+1).
Bảng 3: Field mapping
| Cột UI |
Field Directus đọc |
Tính toán thêm? |
Đúng/Sai |
| Tên |
meta_catalog.name |
Không |
Đúng |
| Mã |
meta_catalog.code |
Không |
Đúng |
| Số lượng |
meta_catalog.record_count |
Không |
Đúng |
| Thực tế |
meta_catalog.actual_count |
Không |
Đúng |
| Baseline |
meta_catalog.baseline_count |
Không |
Đúng |
| Mồ côi |
v_registry_summary.total_orphans |
Không (từ PG) |
Đúng |
| Crosscheck |
v_registry_counts.cross_check |
Không (từ PG) |
Đúng |
| Tạo/Xóa |
registry_changelog count |
CÓ (client-side) |
Nên chuyển PG |
Bảng 4: File inventory
| File |
Status |
Dòng bẩn |
Lý do |
| pages/registries/index.vue |
SẠCH |
— |
readItems + render |
| pages/registries/all/index.vue |
MINOR |
97-103 |
N+1 query pattern |
| pages/registries/[entityType]/index.vue |
MINOR |
47-63, 72-86 |
Client-side changelog aggregation |
| pages/registries/[entityType]/[id].vue |
SẠCH |
— |
Config/discovery mode |
| components/registries/SectionFields.vue |
SẠCH |
— |
Key-value display |
| components/registries/SectionRelation.vue |
SẠCH |
— |
readItems related |
| components/registries/SectionDependency.vue |
SẠCH |
— |
readItems deps |
| components/registries/DiscoveryView.vue |
MINOR |
46-101 |
N+1 for parent/child discovery |
| components/registries/AutoLinkedValue.vue |
SẠCH |
— |
Regex auto-link |
| server/api/registry/refresh-counts.post.ts |
MINOR |
138,141 |
Hardcode CAT-ALL, CAT-999 exclusion |
| config/detail-sections.ts |
SẠCH |
— |
Declarative config |
Tổng: 11 files. 7 SẠCH, 4 MINOR issues (performance + 1 hardcode).
Bảng 5: Orphan analysis
| Nguồn |
Giá trị |
Công thức |
Đúng/Sai |
| v_registry_summary.total_orphans |
0 |
PG pre-computed |
Đúng |
| meta_catalog.orphan_count |
0 (all entries) |
Set by refresh-counts API |
Đúng |
| Nuxt client-side |
0 |
KHÔNG tính — đọc PG trực tiếp |
Đúng |
Kết luận: Orphan = 0 hiện tại. Nuxt không tự tính orphan.
Bảng 6: Server API bypass check
| File |
Đọc từ |
PG direct? |
Vi phạm §0-AV? |
| refresh-counts.post.ts |
Directus REST API ($fetch) |
KHÔNG |
KHÔNG |
| discovery/relations.get.ts |
Directus REST API ($fetch) |
KHÔNG |
KHÔNG |
| transitive/[code].get.ts |
Directus REST API ($fetch) |
KHÔNG |
KHÔNG |
Kết luận: 0 PG bypass. Tất cả qua Directus SDK/API.
Bảng 7: Directus vs Agent Data sync
| Data point |
Directus |
Agent Data |
Khớp? |
| meta_catalog count |
152 entries |
Synced via DOT flows |
Cần verify |
Lưu ý: meta_catalog sync Directus→Agent Data qua DOT flows. Chưa verify trực tiếp trong mission này.
Bảng 8: Scale test
| Kiểm tra |
Hardcode? |
Scale OK? |
Rủi ro |
| meta_catalog readItems |
KHÔNG |
CÓ — dynamic |
OK |
| v_registry_counts readItems |
KHÔNG |
CÓ — reads table |
OK |
| all/index.vue N+1 |
KHÔNG hardcode |
KHÔNG — O(N) queries |
Chậm khi 500+ collections |
| changelog fetch limit:-1 |
KHÔNG hardcode |
KHÔNG — grows with data |
Chậm khi 100K+ changelog |
| detail-sections.ts config |
6 entity types configured |
CÓ — fallback DiscoveryView |
OK |
| refresh-counts CAT-ALL/999 |
CÓ |
KHÔNG — code change breaks |
Nhỏ |
Bảng 9: Guard hiện có
| Guard |
Có? |
Cover registries? |
Đề xuất |
| CI build check |
CÓ |
Build pass only |
Không đủ |
| Critical files check |
CÓ |
KHÔNG registries-specific |
Thêm |
| incomex-rules.md |
CÓ |
KHÔNG mention registries |
Thêm §0-BA rule |
| DOT scanner |
CÓ |
Scanner giám sát data |
OK |
Bảng 10: Rủi ro + vi phạm
| Rủi ro |
File:Line |
Nguyên tắc |
Mức |
| v_registry_counts là TABLE không phải VIEW — data stale |
PG table |
§0-BA data freshness |
HIGH |
| CAT-020~023 entity_type=collection thay vì species thật |
meta_catalog data |
Data accuracy |
MEDIUM |
| N+1 queries all/index.vue |
all/index.vue:97-103 |
Performance |
MEDIUM |
| Client-side changelog aggregation |
[entityType]/index.vue:47-63 |
§0-BA should be PG |
LOW |
| Hardcode CAT-ALL/CAT-999 |
refresh-counts.post.ts:138,141 |
§0-AU dynamic |
LOW |
KẾT LUẬN
- Tổng dòng ảo: 0 — Nuxt KHÔNG tạo phantom rows
- Tổng file bẩn: 4 / 11 (MINOR issues only — performance + 1 hardcode)
- Tổng logic vi phạm nghiêm trọng: 0 — no §0-BA violations
- Root cause of display issues: DATA sai (meta_catalog counts 0, v_registry_counts stale TABLE), KHÔNG phải Nuxt code
Đề xuất fix (cho mission riêng):
- v_registry_counts: chuyển từ TABLE → VIEW hoặc thêm refresh trigger. Hiện tại data stale.
- CAT-020~023: fix entity_type từ 'collection' sang species thật (entity_species, species_collection_map, entity_audit_queue, birth_registry).
- all/index.vue N+1: Tạo PG aggregate view thay vì client-side fetch-all.
- [entityType] changelog aggregation: Chuyển sang Directus aggregate query.
- refresh-counts CAT-ALL/CAT-999: Đọc từ meta_catalog field thay vì hardcode.
Guard đề xuất:
- Thêm vào incomex-rules.md: "§0-BA: KHÔNG thêm logic/computed/filter vào web/pages/knowledge/registries/"
- CI guard: nếu registries files changed → require explicit approval comment
Scale risk:
- all/index.vue sẽ timeout khi 500+ collections (N+1 × limit:-1)
- changelog limit:-1 sẽ OOM khi 1M+ entries
Nếu XÓA hết code thừa:
- Layer 1 (dashboard): cần GIỮ changelog grouping (UI feature)
- Layer 2 (entityType): cần GIỮ crosscheck display (UI feature) — nhưng chuyển calculation sang PG
- Layer 3 (detail): SẠCH — giữ nguyên
- KHÔNG ảnh hưởng chức năng nếu chuyển aggregation sang PG views
S146-M1 DONE | 0 phantom rows | 0 critical violations | 5 đề xuất fix | Chờ anh Huyên duyệt