You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A receipt with N lines issues N separate INSERT statements, i.e. N Postgres round trips inside the receiving transaction. For a large inbound receipt (e.g. 50 lines) that is 50 round trips where one suffices.
Context
The outbound sibling PgOrderRepo.insert_order already uses the batched executemany form (closed via #18) and documents the asyncpg subtlety in a comment: passing a list of dicts alongside the bare insert() construct triggers executemany, whereas table.insert().values(list) does not. The receipt path was simply missed when the order path was converted, so the two inbound/outbound insert routines are now inconsistent.
Proposed fix
Mirror insert_order exactly — a single multi-row insert, guarded against an empty line list:
Summary
PgReceiptRepo.insert_receiptinserts receipt lines one row per round trip:A receipt with N lines issues N separate
INSERTstatements, i.e. N Postgres round trips inside the receiving transaction. For a large inbound receipt (e.g. 50 lines) that is 50 round trips where one suffices.Context
The outbound sibling
PgOrderRepo.insert_orderalready uses the batched executemany form (closed via #18) and documents the asyncpg subtlety in a comment: passing a list of dicts alongside the bareinsert()construct triggers executemany, whereastable.insert().values(list)does not. The receipt path was simply missed when the order path was converted, so the two inbound/outbound insert routines are now inconsistent.Proposed fix
Mirror
insert_orderexactly — a single multi-row insert, guarded against an empty line list:Notes
if lines:guard matchesinsert_orderand avoids executing with an empty parameter list.insert_receiptcoverage should continue to pass; consider asserting the batched form the way Batch PgOrderRepo.insert_order line inserts (avoid N+1) #18 did for orders if that test exists.