fix(tx): order the whole transaction set, not just the loaded page - #284
Merged
Merged
Conversation
The transactions table's column headers carry a sort arrow, and that arrow is a claim about the WHOLE dataset: the pager below it counts the backend's `total` (30 rows, "1 2 3 / 3 · 30 rows") and the summary card above it is a backend aggregate. The ordering, however, only ever applied to the page in hand. `#135` turned the list into a server-paged table (`serverPaging` = backend total, one page of rows per request, `LIMIT/OFFSET` over `ORDER BY t.id DESC`), while sorting stayed where it was born in the static prototype (`#7`, `d70e032`): client-side, over whatever rows the caller passed in -- if (state.sort.length) { data = data.slice().sort(...) } const pageRows = serverPaging ? data : data.slice(...) a page. So clicking "Points" ▲ reordered the ten rows on screen and painted ▲, while the row that actually holds the minimum sat on page 2/3 and was never fetched; the request never changed. The column FILTERS travelled the other half of that road long ago (`#232` `e7bfc6f` / C2114: "local filter of the current page" -> "backend full-dataset filter"); the sort half never did. Fix: one claim, three carriers, and a server that renders `ORDER BY` from a whitelist. * `ui/js/app.js` — `txSortParams()` projects the single sort state (`txTable.sort`) into the LIST request only (the trend endpoint buckets by time; row order means nothing to it). `txQuerySig()` now covers the sort, so the reload guard refetches when a header is clicked -- without that line the arrow would move over a list that does not, which is worse than the defect being fixed. The local sort steps aside when the call site declares `serverSort`: `if (state.sort.length && !(serverPaging && serverSort))`. * `src/routes/wallet.rs` — `TX_SORT_KEYS` (11 keys, exactly the sortable columns of `TX_COLUMNS`) + `tx_sort_expr()` + `tx_order_by()`. The user string never reaches SQL; the `ORDER BY` fragment is rendered from the whitelist, always with a trailing `, t.id DESC` (a non-unique sort makes `LIMIT/OFFSET` page boundaries indeterminate -- one row twice, another never), and an unknown key / mismatched key-direction count / bad direction is a 400. Validation runs before the DB lock, as `type` does. Expressions match what the cell shows (`pts` via `signed_pts_expr`, the four token columns on their raw values, `model`/`key` byte-identical to the filter expressions). Tests: * `state_gate::the_sort_indicator_and_the_order_by_share_one_source` — four rules, each with its own mutant leg, plus a `the_r164_rules_have_teeth` self-proof over self-contained mini sources and a `the_r164_roster_is_real` positive control. Roster == whitelist == match arms, `q.sort`/`q.dir` bound in exactly one place, the guard reads the WHOLE condition (a `[^)]*` reader cannot see `!(a && b)`) and a control rule keeps the filter half of the same road honest. * `src/routes/wallet.rs` — three behaviour tests: the whole set is ordered (not the page), ties are stable across pages, and anything outside the whitelist is rejected. * jsdom probe (7 legs, both directions): on the pre-fix tree the two global-extremum legs and the "did the request carry sort" leg fail; on the landed bytes all seven pass. The two competing "fixes" (keep sorting the page and caption the arrow " (this page)"; stop painting the arrow) are rejected by the same legs. Scope, stated honestly: the gate is lexical -- it proves the three carriers agree and that the whitelist IS the column roster; it does not prove that the rows on screen are globally ordered (that is the jsdom probe's job, and there is no JS runner in `cargo test`), nor the `ORDER BY` semantics themselves (those are the wallet behaviour tests). Recorded in `ui/README.md`.
Owner
Author
|
Self-review (own PR — recorded as a plain comment because a formal review cannot be submitted on one's own PR). What I checked
Known non-goals, deliberately untouched
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The transactions table's column headers carry a sort arrow, and that arrow is a claim about the whole dataset: the pager under the table counts the backend's
total("1 2 3 / 3 · 30 rows") and the summary card above it is a backend aggregate. The ordering, however, only ever applied to the page in hand.#135turned the list into a server-paged table (serverPaging= backend total, one page of rows per request,LIMIT/OFFSETover a hardcodedORDER BY t.id DESC), while sorting stayed where it was born in the static prototype (#7,d70e032): client-side, over whatever rows the caller passed in — a page. Clicking "Points" ▲ therefore reordered the ten rows on screen and painted ▲, while the row that actually holds the minimum sat on page 2/3, was never fetched, and the request never changed at all. The column filters travelled the other half of that road long ago (#232/e7bfc6f: "local filter of the current page" → "backend full-dataset filter"); the sort half never did.Related Issue
None — found while scanning the transactions view (same family as
#232/#77).Changes
ui/js/app.js— one claim, three carriers:txSortParams()projects the single sort state (txTable.sort) into the list request only. The trend endpoint buckets by time; row order means nothing to it.txQuerySig()now covers the sort, so the reload guard actually refetches on a header click. Without this line the arrow would move over a list that does not — worse than the defect being fixed (C2146's family).serverSort:if (state.sort.length && !(serverPaging && serverSort)).src/routes/wallet.rs— the user string never reaches SQL:TX_SORT_KEYS(11 keys, exactly the sortable columns ofTX_COLUMNS),tx_sort_expr()andtx_order_by(). TheORDER BYfragment is rendered from the whitelist, always with a trailing, t.id DESC(a non-unique sort makesLIMIT/OFFSETpage boundaries indeterminate — one row twice, another never), and an unknown key / mismatched key–direction count / bad direction is a 400. Validation happens before the DB lock, astypedoes. Sort expressions match what the cell shows (ptsviasigned_pts_expr, the four token columns on their raw values,model/keybyte-identical to the filter expressions).ui/index.html— cache-bust token bumped for theapp.jschange.ui/README.md— the convention ("one claim, three carriers" + the whitelist rule) and the gate's honest lexical scope.Tests
cargo test— 342 passed / 0 failed (baseline52aec72: 336; +6 = 3 gate tests + 3 wallet behaviour tests)cargo fmt --check— cleancargo clippy --all-targets -- -D warnings— cleanstate_gate::the_sort_indicator_and_the_order_by_share_one_source(4 rules, each with its own mutant leg),the_r164_rules_have_teeth(self-proof over self-contained mini sources),the_r164_roster_is_real(positive control);src/routes/wallet.rs: the whole set is ordered (not the page), ties are stable across pages, anything outside the whitelist is rejected.git archive 52aec72 src ui): declared red there ={ the_sort_indicator_and_the_order_by_share_one_source, the_r164_roster_is_real }, actual red = the same two; on the landed tree, 47/47 green.rustfmt+clippy-driver -D warningslegs on both trees.index.html+ the four real scripts, a paging/sortable fetch stub over a 30-row fixture where the global min and max sit on pages 2 and 3): pre-fix tree → the two global-extremum legs and the "did the request carrysort" leg fail (as declared); landed bytes → all seven pass. The two competing "fixes" — keep sorting the page and caption the arrow " (this page)", or stop painting the arrow — are rejected by the same legs.Honest scope: the gate is lexical — it proves the three carriers agree and that the whitelist IS the column roster. It does not prove that the rows on screen are globally ordered (that is the jsdom probe's job; there is no JS runner in
cargo test), nor theORDER BYsemantics themselves (those are the wallet behaviour tests). Recorded inui/README.md.Checklist
fix/…)signed_pts_expr/ filter expressions)