KB-649F
S146-M2 Registries Display Fix Report
3 min read Revision 1
reports146registriesv_registry_countsstale-dataauto-refresh
S146-M2: Fix Registries Display — v_registry_counts Stale
Date: 2026-03-29 | OR: v7.4 | Task: TSK-012
Root Cause
v_registry_counts was a TABLE with 23 stale rows (last updated before Dieu 26 v3.5). 30 counting triggers DISABLED → no one updated it. Nuxt reads both meta_catalog (correct) + v_registry_counts (stale) → crosscheck shows massive discrepancies.
Fix Applied — Cách A Modified
Bước 2.1a: Fix meta_catalog consistency
- actual_count ≠ record_count: 12 entries fixed
- baseline_count NULL: 73 entries fixed
- orphan_count NULL: 125 entries fixed
Bước 2.1b-c: TABLE replacement
- Old TABLE (23 rows, stale) → DROPPED (Directus DELETE cascaded)
- New TABLE (152 rows, auto-refreshed) created with same schema
- PG trigger
trg_meta_catalog_refresh_viewsfires on meta_catalog INSERT/UPDATE/DELETE - Calls
refresh_registry_views()which TRUNCATE + repopulate from meta_catalog
Why TABLE not VIEW?
Directus 11.x cannot serve VIEWs (schema=null → FORBIDDEN). TABLE with auto-refresh trigger = functionally equivalent to VIEW but Directus-compatible.
v_registry_summary: same treatment
- Old TABLE (1 row, stale) → DROPPED + recreated as auto-refreshed TABLE
- Aggregate from meta_catalog (excluding CAT-ALL)
Verification
| Check | Result |
|---|---|
| v_registry_counts rows | 152 (was 23) ✅ |
| NULL in orphan_count/record_count | 0 ✅ |
| LỆCH (cross_check) | 0 ✅ |
| Directus admin API | 200, data correct ✅ |
| Directus public API | 200, data correct ✅ |
| Nuxt /knowledge/registries | 200 ✅ |
| Scanner orphan | 0 ✅ |
| DOT-152 accuracy | 140 healed, 0 escalated ✅ |
Sample Data Verify
| cat_code | view_count | meta_count | cross_check |
|---|---|---|---|
| CAT-000 | 152 | 152 | KHỚP |
| CAT-006 | 152 | 152 | KHỚP |
| CAT-008 | 145 | 145 | KHỚP |
| CAT-023 | 21179 | 21179 | KHỚP |
| CAT-ALL | 44261 | 44261 | KHỚP |
Data Model After Fix
meta_catalog (SSOT, record_count = COUNT(*))
↓ PG trigger (auto on INSERT/UPDATE/DELETE)
v_registry_counts (TABLE, auto-refreshed)
v_registry_summary (TABLE, auto-refreshed)
↓ Directus API
Nuxt (readItems → render)
Refresh chain:
DOT-152 daily → refresh meta_catalog counts
→ trigger fires → v_registry_counts/summary repopulated
→ Nuxt loads → fresh data
§0-AW
- v_registry_counts auto-refreshed on meta_catalog change: CÓ ✅
- Dual-trigger: PG trigger (event) + DOT-152 (cron+ODM): CÓ ✅
- 0 Nuxt files changed: CÓ ✅
Guard
- PG COMMENT on both tables: "Auto-refreshed from meta_catalog. S146-M2."
- DOT-152 checks accuracy daily
- Trigger ensures freshness on any meta_catalog write
S146-M2 DONE | 23→152 rows | 0 LỆCH | 0 NULL | Auto-refresh trigger | 0 Nuxt changes