Commit 09abcfa
authored
fix(core-flows): filter reservations by line item in createOrderFulfillmentWorkflow (#16136)
Fixes #16135
**What**
Renames the `variables` key of the `get-reservations` remote query in `createOrderFulfillmentWorkflow` from `filter` to `filters`, and adds a changeset (patch bump for `@medusajs/core-flows`).
**Why**
`RemoteQuery.fetchRemoteData` only recognizes the arg names `filters`, `context`, and the pagination options — any other arg is silently dropped. Because the query passes its `line_item_id` constraint under `filter` (singular), the constraint never reaches the module, and since the entry point is queried without ids, `take` is set to `null`. Every fulfillment creation therefore executes `listReservationItems({}, { take: null })`, fetching and hydrating **every reservation item in the database** and then using only the entries belonging to the fulfilled line items (via `buildReservationsMap`).
Results are functionally correct, so this went unnoticed, but the cost scales with the total number of reservations. On our production store (~286k reservation items from per-location reservations across 75 stock locations), each fulfillment creation seq-scans the full table and blocks the Node.js event loop for ~50 seconds, during which the API process serves no other requests. Details and evidence in #16135.
**How**
One-character fix: `filter` → `filters` in the `useRemoteQueryStep` call, so the `line_item_id` filter is pushed down to the inventory module query.
**Testing**
- Verified against production data via a patched `@medusajs/core-flows` (pnpm patch with this exact change): fulfillment creation drops from ~50s to well under a second, and `pg_stat_user_tables` shows no further full scans of `reservation_item`.
- The fulfillment flow behaves identically otherwise: `buildReservationsMap` already keyed by `line_item_id`, so downstream steps (`prepareFulfillmentData`, `prepareInventoryUpdate`) receive the same reservations for the fulfilled items as before.1 parent de9b40c commit 09abcfa
2 files changed
Lines changed: 13 additions & 1 deletion
File tree
- .changeset
- packages/core/core-flows/src/order/workflows
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
521 | 521 | | |
522 | 522 | | |
523 | 523 | | |
524 | | - | |
| 524 | + | |
525 | 525 | | |
526 | 526 | | |
527 | 527 | | |
| |||
0 commit comments