Commit 081e0d3
refactor(loops): collapse data.rows page-slice SQL into one whitelisted query (CoreBunch#159)
The data.rows loop source repeated the same ~35-line SELECT twelve times
(6 orderBy/direction branches x 2 table kinds), differing only in the
ORDER BY line. Adding a column to the projection meant editing twelve
copies — a drift trap.
Each table kind now has ONE query. The ORDER BY clause is composed from
a closed, compile-time column map (POST_TYPE_ORDER_COLUMN /
DATA_KIND_ORDER_COLUMN); orderBy is whitelisted against ALLOWED_ORDER_BY
and direction narrowed to 'asc' | 'desc' before either reaches the SQL
text, and every runtime value (tableId, limit, offset) rides as a
positional parameter via db.unsafe — the same dialect-aware pattern
resolveMediaIdsToPaths already used. Both DB adapters run identical
row normalization (_json hydration, Date → ISO) on the unsafe path, so
read semantics are unchanged.
New dataRowsFetch.test.ts locks the behavior against a real migrated
SQLite DB: every orderBy x direction ordering for both table kinds, the
publishedAt → createdAt mapping on data-kind tables, status/soft-delete
filtering, pagination with stable totalItems, the full LoopItem field
projection, and unknown-input fallbacks. The suite passed against the
old branchy implementation before the swap and passes unchanged after.
dataRows.ts drops 903 → 540 lines and graduates from the module-size
grandfathered ledger.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>1 parent 6d06865 commit 081e0d3
3 files changed
Lines changed: 540 additions & 471 deletions
File tree
- src
- __tests__
- architecture
- loops
- core/loops/sources
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
100 | 103 | | |
101 | 104 | | |
102 | 105 | | |
| |||
0 commit comments