Repository navigation
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2490 +/- ##
==========================================
+ Coverage 79.05% 79.06% +0.01%
==========================================
Files 387 387
Lines 105617 106020 +403
==========================================
+ Hits 83494 83824 +330
- Misses 22123 22196 +73 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
crodas
left a comment
There was a problem hiding this comment.
Overall looks good, but we cannot panic outside of tests
| let unit = column_as_string!(&row[2], CurrencyUnit::from_str); | ||
| Ok(Issuance::new( | ||
| Amount::from_i64(column_as_number!(row[0].clone())) | ||
| .expect("Is amount when put into db") |
There was a problem hiding this comment.
Can we throw an error instead of panicking?
There was a problem hiding this comment.
Fixed in e0f8789 and retained after the latest sync. The issuance amount conversion now returns ConversionError::InvalidConversion instead of using expect(), so invalid database values are propagated as errors rather than panicking.
| .map(|i| { | ||
| Issuance::new( | ||
| Amount::from_i64(i.amount) | ||
| .expect("Is amount when put into db") |
There was a problem hiding this comment.
Fixed in e0f8789 as well. The batched issuance reconstruction path now converts the raw value before storing it in RawQuoteIssuance and propagates the same ConversionError on invalid values, so this path no longer panics either.
|
@cdk-bot review |
cdk-bot
left a comment
There was a problem hiding this comment.
Verified findings approved for disclosure:
- New test's quote4 comment claims "0 payments, 2 issuances" but fixture adds a payment; issuance-only reconstruction case never exercised (low) - see inline comment
Additional locations included in summary:- crates/cdk-common/src/database/mint/test/mint.rs:2141
| None, | ||
| ); | ||
|
|
||
| // Quote 4: 0 payments, 2 issuances (multiple issuance) |
There was a problem hiding this comment.
Provenance: lane:persona (persona review lane; the cashu domain skill was requested per the lane methodology but unavailable in this environment).
Root cause (PR-introduced): The new test mint_quotes_load_payments_and_issuance_without_duplicates in crates/cdk-common/src/database/mint/test/mint.rs defines quote4 with a comment claiming "0 payments, 2 issuances" (the issuance-only edge case, line 2063), but the fixture then adds 1 payment to it (lines 2141–2152, add_payment("quote4_pay_1")), so the quote meant to exercise "multiple issuance with no payments" is actually a 1-payment/2-issuance quote. The verifier (verify_q4, lines 2194–2199) matches the actual fixture (q.payments.len() == 1), so the test passes, but the comment at line 2063 and the coverage summary near line 2204 ("Single quote lookups (zero payments/issuance, multiple payments, multiple issuance, multiple of both)") misdescribe what is tested.
Impact: The specific reconstruction case "quote has issuance rows but no payment rows" — where attach_relations_to_quotes in crates/cdk-sql-common/src/mint/quotes.rs must leave quote.payments empty while populating quote.issuance — is never exercised, despite being the case the fixture was named for. The attach logic is symmetric (two independent if let Some(...) branches), so the untested combination is low-risk, but a future regression that, e.g., only attaches payments or cross-links rows when both relations exist would not be caught by this test. The contradictory comment also misleads future maintainers about the fixture's shape.
Fix: Either (a) remove the add_payment block for quote4 (lines ~2141–2152) so it truly has 0 payments and 2 issuances, and update verify_q4 to assert 0 payments — this actually covers the issuance-only case; or (b) keep the fixture as-is and correct the comment at line 2063 to "1 payment, 2 issuances" and adjust the section comment so the claimed coverage matrix matches reality.
There was a problem hiding this comment.
Fixed in e7423b2. Quote4 is now a genuine issuance-only fixture with 0 payments and 2 issuances, and verify_q4 asserts that shape. The batch and get-all paths now explicitly exercise relation reconstruction when issuance is present without any payment rows.
|
Hi @crodas, thanks for the review! In commit
All unit, SQLite, and clippy checks pass cleanly. |
Description
Closes #2435
Eliminates the N+1 query pattern when fetching mint quotes in
cdk-sql-commonby batch loading related child records (mint_quote_paymentsandmint_quote_issued) using constant queries instead of looping per quote.Before:$1 + 2N$ queries for $N$ quotes.$3$ queries constant (1 for parent quotes, 1 for payments belonging to those quotes, 1 for issuances belonging to those quotes).
After:
Key details:
CurrencyUnitfor child payments and issuances, avoiding redundant joins back tomint_quote.quote_idin Rust (HashMap<String, Vec<...>>) and attaches them to eachMintQuote.None, and repeated ID semantics inget_mint_quotes_inner.SELECT ... FOR UPDATEacquires row locks onmint_quotefirst, and relations are read while the lock is held.crates/cdk-sqlite/src/async_sqlite.rsunchanged.Notes to the reviewers
crates/cdk-common/src/database/mint/test/mint.rs(mint_quotes_load_payments_and_issuance_without_duplicates) covering:Noneget_mint_quoterelations loading with row lockingSuggested CHANGELOG Updates
CHANGED
cdk-sql-commonto resolve N+1 queries (Refactor: Use JOIN to get Mint Quotespaymentsandissuance#2435).Checklist
just quick-checkbefore committingcrates/cdk-ffi)