Repository navigation
feat(transactions): break the summary down by API key - #446
Merged
Merged
Conversation
The transactions page has one number per metric once filtered: nothing says which API key spent it. The detail table carries a key name per row, and the only per-key aggregate in the codebase is the sharing page's, which sums what an owner earns rather than what a consumer spends. Add a `by_key` array to the existing `GET /api/transactions` response instead of a second endpoint. It shares the same `where_sql` and the same binds as `summary`, so "the groups add up to the summary" holds structurally rather than by two parameter lists being kept in step -- the drift this repository already paid for once when `expire` reached the list endpoint but not the trend one. Three conventions the grouping inherits, each with a test: - it reads the `tx_facts` view, not `transactions`: details are kept for `[rollup] retain_minutes` only and older history exists solely as minute rollup rows; - the group key is the view's `api_key_id`, not the rollup table's, which uses `0` as its NULL sentinel; - entries are `SUM(row_count)`, not `COUNT(*)` -- the latter counts view rows, i.e. minute buckets. Rows with no API key (provider-side earn / topup / expire / withdraw) form an explicit group ordered last, because dropping them is what would break the sum. The key name comes from a scalar subquery rather than a fourth LEFT JOIN: any of the three joins in `tx_joins()` makes SQLite abandon the covering index and re-read the table (0.21s -> 22.6s on the dev database). The page renders the array under the summary cards from the same payload, so changing a filter costs no extra request.
argszero
added a commit
that referenced
this pull request
Nov 12, 2026
Two commits since v0.7.34, no schema change (still 18): - #445 lets an API key be paused and resumed instead of only revoked. - #446 breaks the transactions summary down by API key. The version string moves in the five carriers deploy_gate guards: Cargo.toml, Cargo.lock, Dockerfile (three places), docker-compose.yml (two) and the new CHANGELOG heading. Co-authored-by: argszero <argszero@argszerodeMac-mini.local>
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 page gives one number per metric for whatever filters are set, and nothing that says which API key spent it. The detail table carries a key name on every row, but that is per row; the only per-key aggregate in the tree is the sharing page's, which sums what an owner earns rather than what a consumer spends. This adds the missing reading: the same filters, grouped by API key.
It extends
GET /api/transactionswith aby_keyarray rather than adding a second endpoint. The grouping has to use the same filters as the detail list (time range, custom bounds, type tab, six column filters), and sharing one response means it shares the samewhere_sqland the same binds — so "the groups add up tosummary" holds structurally instead of depending on two parameter lists staying in step. This repository has already paid for that failure once: anexpirevalue accepted by the list endpoint and rejected by the trend one. A separate endpoint would also need a third copy of the query and time parsers, and would changeTxQuery, whichstate_gate.rspins.Three conventions the aggregate inherits, each with a test:
tx_factsview, nottransactions. Details are kept for[rollup] retain_minutesonly; anything older exists solely as minute rollup rows, so reading the raw table would undercount history.api_key_id, not the rollup table's. The rollup table uses0as its NULL sentinel; the view restores it withNULLIF(…, 0). Grouping on the rollup table would fold every keyless row into a group withid = 0.SUM(row_count), notCOUNT(*). The latter counts view rows, i.e. minute buckets. The test fixture folds twoconsumerows in the same minute into one view row withrow_count = 2specifically so these two part ways.Rows with no API key — provider-side
earn/topup/expire/withdraw— form an explicit group ordered last, because silently dropping them is exactly what would break the sum. The key name comes from a scalar subquery rather than a fourthLEFT JOIN: any of the three joins intx_joins()makes SQLite abandon the covering index and re-read the table (0.21s → 22.6s on the dev database over NFS), andsrc/perf_gate.rsguards that invariant. Its positive control counts the aggregate statements that go throughtx_joins_if, so it moves from three to four with a comment naming the fourth.The page renders the array under the summary cards from the same payload, so changing a filter costs no extra request.
Files
src/routes/wallet.rs—by_key_sql/by_key_rows, wired into thetransactionshandler; testssrc/perf_gate.rs— positive control 3 → 4 with the reasonsrc/i18n_pack.rs— re-pinned counts after six new keysui/index.html,ui/js/app.js,ui/js/i18n.js— the#tx-by-keycard,renderTxByKey(), six keys in both packsdocs/architecture.md,ui/README.md— the endpoint line and the card's contractTests
cargo test— 614 passed, 0 failedcargo clippy --all-targets -- -D warnings— cleancargo fmt --check— cleanroutes::wallet::tests::by_key_splits_the_summary_by_api_key_and_keeps_the_keyless_group,routes::wallet::tests::by_key_survives_folding_and_deletion_of_the_details,routes::wallet::tests::counting_view_rows_would_undercount_the_per_key_entries,tx_facts::tests::counting_view_rows_is_not_counting_calls)Related Issue
No issue — this is acceptance item ② of an internal work order (rant 2026-11-12T14:13:23), whose item ① landed as #445.