fix(core-flows): filter reservations by line item in createOrderFulfillmentWorkflow#16136
Conversation
🦋 Changeset detectedLatest commit: b363785 The changes in this PR will be included in the next version bump. This PR includes changesets to release 79 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Thanks for the contribution! Initial automated review looks good. Correct one-line fix renaming the get-reservations remote query variable from 'filter' to 'filters' in createOrderFulfillmentWorkflow, so the line_item_id constraint is actually pushed down instead of loading every reservation item. Verified against the sibling cancel-order-fulfillment workflow, which uses the same filters/line_item_id pattern, and buildReservationsMap keys by line_item_id so downstream behavior is unchanged. PR template is complete, a proper patch changeset is included, and it links open issue #16135. Triggered by: new PR opened |
Fixes #16135
What
Renames the
variableskey of theget-reservationsremote query increateOrderFulfillmentWorkflowfromfiltertofilters, and adds a changeset (patch bump for@medusajs/core-flows).Why
RemoteQuery.fetchRemoteDataonly recognizes the arg namesfilters,context, and the pagination options — any other arg is silently dropped. Because the query passes itsline_item_idconstraint underfilter(singular), the constraint never reaches the module, and since the entry point is queried without ids,takeis set tonull. Every fulfillment creation therefore executeslistReservationItems({}, { take: null }), fetching and hydrating every reservation item in the database and then using only the entries belonging to the fulfilled line items (viabuildReservationsMap).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→filtersin theuseRemoteQueryStepcall, so theline_item_idfilter is pushed down to the inventory module query.Testing
@medusajs/core-flows(pnpm patch with this exact change): fulfillment creation drops from ~50s to well under a second, andpg_stat_user_tablesshows no further full scans ofreservation_item.buildReservationsMapalready keyed byline_item_id, so downstream steps (prepareFulfillmentData,prepareInventoryUpdate) receive the same reservations for the fulfilled items as before.