Avoid loading the order collection twice for customer orders GraphQL query - #41086
Open
thai2301 wants to merge 3 commits into
Open
Avoid loading the order collection twice for customer orders GraphQL query#41086thai2301 wants to merge 3 commits into
thai2301 wants to merge 3 commits into
Conversation
Querying customer { orders { items { items } } } loaded the sales order
collection twice: once in CustomerOrders::resolve (for the orders list)
and again in OrderItem\DataProvider::fetchOrders(), which re-queried the
same orders to attach currency/store/discount data to each order item.
The item resolvers already hold the fully-loaded parent OrderInterface,
so they now hand it to the provider via a new addOrder() method, and
fetchOrders() reuses those, querying only the order ids that were not
provided. The Resolver\OrderItem (nested child items) path keeps working
through that fallback. Eliminates the duplicate order collection load.
|
Hi @thai2301. Thank you for your contribution!
Allowed build names are:
You can find more information about the builds here For more details, review the Code Contributions documentation. |
5 tasks
Author
|
@magento run all tests |
getItemId() surfaces a DB value as a string and the provider passes it to base64_encode(); the mock returned an int, tripping base64_encode()'s string type in the new tests. Return it as a string, matching production.
Author
|
@magento run all tests |
Author
|
@magento run all tests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fetching
customer { orders { items { items } } }via GraphQL loads the sales order collection from the database twice:Magento\SalesGraphQl\Model\Resolver\CustomerOrders::resolve()loads the customer's orders (orderRepository->getList()) and passes each fully-loadedOrderInterfacedown as$value['model'].itemsare resolved,Magento\SalesGraphQl\Model\OrderItem\DataProvider::fetchOrders()re-queriesorderRepository->getList()for the very same orders, only to read each item's currency / store id / discount data.The item resolvers already have the loaded parent order in hand, so there is no need to reload it. This adds an
addOrder(OrderInterface $order)method to the data provider; the resolvers that own the order model (OrderItems,Invoice\InvoiceItems,CreditMemo\CreditMemoItems) register it, andfetchOrders()starts from those provided orders and queries the repository only for order ids that were not provided.The
Resolver\OrderItempath (nested child/bundle items, which only holds a parent order item, not the order) continues to work through that fallback, so behavior is unchanged for callers that don't provide an order. Keying is bysales_order.entity_id(thesales_order_item.order_idforeign key target), matching the previous lookup.Related Issue
Fixes #40966
Manual testing scenarios
sales_ordercollection is loaded twice (once byCustomerOrders, once byOrderItem\DataProvider::fetchOrders).Questions or comments
None.
Contribution checklist