refactor(tables): consolidate row data-access in service.ts#4881
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview Row listing: Internal and v1 GET handlers now call shared CSV import: The import route delegates to Position & deletes: Shared helpers ( Reviewed by Cursor Bugbot for commit 77d6a14. Bugbot is set up for automated code reviews on this repo. Configure here. |
|
@greptile review |
Greptile SummaryThis refactor centralizes all
Confidence Score: 5/5Safe to merge; the refactor is behavior-preserving across all read, write, and import paths. All route wire shapes, transaction boundaries, advisory-lock usage, and position compaction logic are faithfully reproduced in the new helpers. The only notable side effect is a redundant advisory-lock round-trip in apps/sim/lib/table/service.ts — the Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Route or Tool] -->|read| B[queryRows]
B --> C{includeTotal?}
C -->|yes| D["Promise.all: COUNT + SELECT"]
C -->|no| E[SELECT only]
D --> F{withExecutions?}
E --> F
F -->|true| G[loadExecutionsByRow]
F -->|false| H[skip sidecar join]
G --> I[QueryResult]
H --> I
A2[Import Route] -->|append| J[importAppendRows]
A2 -->|replace| K[importReplaceRows]
J --> L["db.transaction: addTableColumnsWithTx + batchInsertRowsWithTx batches"]
K --> M["db.transaction: addTableColumnsWithTx + replaceTableRowsWithTx"]
L --> N[acquireRowOrderLock + reserveBatchPositions]
M --> N
A3["insertRow / upsertRow"] --> O["insertOrderedRow / reserveInsertPosition"]
O --> N
A4[deleteRow] --> P["deleteOrderedRow: shiftRowsDownAfter"]
A5["deleteRowsByIds / deleteRowsByFilter"] --> Q["deleteOrderedRowsByIds: compactPositions"]
Reviews (5): Last reviewed commit: "refactor(tables): consolidate row data-a..." | Re-trigger Greptile |
Greptile SummaryThis PR centralizes all
Confidence Score: 4/5Safe to merge; the refactor is behavior-preserving and all position primitives map 1-to-1 with the code they replaced. All SQL in the new wrapper is identical to what it replaces, workspace-scoping and advisory-lock ordering are unchanged, and the 15 new unit tests cover the key branching paths. The one change worth watching is that apps/sim/lib/table/table-wrapper.ts — the sequential count+select path for Important Files Changed
Sequence DiagramsequenceDiagram
participant IR as Internal Route
participant V1 as v1 Route
participant SVC as service.ts queryRows()
participant TW as table-wrapper.ts queryRows()
participant DB as Postgres
IR->>TW: "queryRows(table, {withExecutions: true})"
V1->>TW: "queryRows(table, {withExecutions: false})"
SVC->>TW: queryRowsWrapper(table, options)
TW->>DB: "COUNT(*) WHERE tableId+workspaceId+filter [if includeTotal]"
DB-->>TW: totalCount
TW->>DB: "SELECT * FROM user_table_rows ORDER BY position/sort LIMIT/OFFSET"
DB-->>TW: rows[]
TW->>DB: "SELECT * FROM table_row_executions WHERE rowId IN (...) [if withExecutions]"
DB-->>TW: executions[]
TW-->>IR: QueryResult rows, rowCount, totalCount, executions
TW-->>V1: "QueryResult rows, rowCount, totalCount, executions={}"
TW-->>SVC: QueryResult
Reviews (2): Last reviewed commit: "refactor(tables): centralize row read/or..." | Re-trigger Greptile |
|
@greptile review |
|
@greptile review |
- Route both row-GET endpoints (internal + v1) and the copilot tool through the single service.queryRows instead of three inline query copies; add a withExecutions option so the public v1 route still omits executions. - Run COUNT(*) and the page fetch concurrently in queryRows. - Move CSV-import transaction ownership out of the API route into importAppendRows / importReplaceRows so routes never hold a trx. - Extract row position mechanics (reserve / shift / compact) into named private helpers in service.ts; no separate table-wrapper module.
2860fe6 to
77d6a14
Compare
|
@greptile review |
Summary
service.queryRowsinstead of three inline query copies; add awithExecutionsoption so v1 still omits executions.COUNT(*)and the page fetch concurrently inqueryRows(was two serial round-trips).importAppendRows/importReplaceRowsso routes never hold atrx.service.ts— readable, and a single locus for the planned fractional-indexing change.service.ts); no separate wrapper layer.Type of Change
Testing
Tested manually. 244 table / import / row-route / copilot tests pass;
type-check,bun run lint:check, andbun run check:api-validation:strictall clean.Checklist