The take screen reads the whole trade history to answer one order's rows
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 55/100
Research direction
Start with tradeRoleLookupProvider, the storage trait in db/mod.rs, and the existing SQLite and IndexedDB implementations; trade_document_by_order_id is noted as a reference for the IndexedDB path. Check the expression index in schema.rs and the matching query in sqlite.rs, then trace the Rust API and regenerate its bindings. Done means the take check reads only that order's rows, still handles multiple rows and unreadable storage, and the contract and tests are updated.
Written by the indexing model from the issue text.
Description
Summary
tradeRoleLookupProvider asks whether the user already takes part in an order by reading every trade row and filtering in Dart:
participatingRole(await readTrades(), orderId)
list_trades runs SELECT id, data FROM trades ORDER BY started_at DESC, serde_json-decodes every blob, and flutter_rust_bridge copies the whole Vec<TradeInfo> across — to keep, at most, the rows of one order. The take screen asks twice per take: once from initState (the participant redirect) and again on the Take tap, where the latency is felt.
The call it replaced, get_trade_role, went through the expression index instead:
SELECT data FROM trades WHERE json_extract(data, '$.order.id') = ? LIMIT 1
CREATE INDEX IF NOT EXISTS idx_trades_order_id
ON trades(json_extract(data, '$.order.id'));
Raised by @grunch in review of #448, which moved the lookup to Dart because Rust had no "every row of this order" query. LIMIT 1 would not do: a database from before a confirmed take replaced its order's earlier rows can hold two, and a live one among them still makes the user a participant.
Context
This is not a new class of read — rawTradesProvider (My Trades), tradeInfoProvider and _followTradeRow's polling all read the full list. What is new is paying it on the take path, for an account whose history can hold hundreds of closed trades, each with bond and peer snapshots.
Proposal
Add a narrow bridge call, list_trades_for_order(order_id) -> Vec<TradeInfo>, over the existing index, and have tradeRoleLookupProvider read through it. participatingRole stays exactly as it is: a pure rule over the rows it is given, with its own unit tests.
Notes for whoever takes it:
- The
WHERE json_extract(data, '$.order.id') = ?expression must stay byte-identical to the others insqlite.rs, or SQLite falls back to a full scan (see the comment above the index inschema.rs). - It is a new method on the storage trait (
db/mod.rs), so it needs both implementations: SQLite and IndexedDB, wheretrade_document_by_order_idalready shows the shape. rust/src/api/changes mean regenerated bindings committed in the same commit, and a line inspecs/004-mostro-p2p-client/contracts/orders.md.- Keep the seam: the take screen's tests override the reader, not the role lookup, so the rule and its error handling stay under test.
Acceptance
- The take screen's participant check no longer deserialises rows of other orders.
- Two rows for the same order are still both read, so an open one wins over an ended take.
- An unreadable store still answers "not a participant" rather than throwing (the contract
get_trade_rolehad, restored in #448).
Related: #434, #448.
- Dominant language
- Dart
- Stars
- 11
- Forks
- 9
- Avg merge
- 20h 31m
- Merged PRs (30d)
- 231
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from MostroP2P/app
-
area: rust-core bug priority: low
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
area: ui
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
Similar issues
-
c: proposal p: go_router package team-ecosystem
Difficulty 2/5 1-3 hours Newbie friendliness 60/100
flutter/flutter#194542 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
famedly/matrix-dart-sdk#2524 ·
Maintainers usually reply within 1 day
-
Documentation
Difficulty 1/5 Under an hour Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Kazakh (kk_KZ) and Georgian (ka_GE) system locales get English instead of the shipped translationsOpenbug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
area: docs eco: dart good first issue help wanted lane: free-agent roadmap size: XS type: docs
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
arminazimi/evergreen#430 ·
Maintainers usually reply within 1 day