magento2
magento2 copied to clipboard
Updating customer's email takes a lot of time if customer has a lot of orders
Preconditions and environment
- Magento version - 2.4.4
Steps to reproduce
- Create a customer and place 100+ orders with the customer
- Try to change the customer's email using REST API or GraphQL
Expected result
The email change shouldn't take more than a few seconds
Actual result
It is taking around 43 seconds for 107 orders. The time is directly dependent on number of orders placed
Additional information
The \Magento\Customer\Observer\UpgradeOrderCustomerEmailObserver::execute
is the culprit here. Magento is forced to load all of the customer's orders and save them one by one after changing the email. This is not ideal for a store having customer's with high order volume.
This can be optimized by replacing the
$searchCriteria = $this->searchCriteriaBuilder
->addFilter(OrderInterface::CUSTOMER_ID, $customer->getId())
->create();
/**
* @var Collection $orders
*/
$orders = $this->orderRepository->getList($searchCriteria);
$orders->setDataToAll(OrderInterface::CUSTOMER_EMAIL, $customerEmail);
$orders->save();
code with a direct SQL multi-update query of some sort, since we don't need to load the orders. We just need to update all of them. And since sales_order is a flat table, it shouldn't take too much time.
Release note
No response
Triage and priority
- [ ] Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- [ ] Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- [X] Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- [ ] Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- [ ] Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
Hi @jayankaghosh. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:
- Summary of the issue
- Information on your environment
- Steps to reproduce
- Expected and actual results
Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:
@magento give me 2.4-develop instance
- upcoming 2.4.x release
For more details, review the Magento Contributor Assistant documentation.
Add a comment to assign the issue: @magento I am working on this
To learn more about issue processing workflow, refer to the Code Contributions.
- Join Magento Community Engineering Slack and ask your questions in #github channel.
:warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.
:clock10: You can find the schedule on the Magento Community Calendar page.
:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.
:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel
Hi @engcom-Bravo. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
-
[ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
Details
If the issue has a valid description, the labelIssue: Format is valid
will be added to the issue automatically. Please, edit issue description if needed, until labelIssue: Format is valid
appears. -
[ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add
Issue: Clear Description
label to the issue by yourself. -
[ ] 3. Add
Component: XXXXX
label(s) to the ticket, indicating the components it may be related to. -
[ ] 4. Verify that the issue is reproducible on
2.4-develop
branchDetails
- Add the comment@magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on2.4-develop
branch, please, add the labelReproduced on 2.4.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here! -
[ ] 5. Add label
Issue: Confirmed
once verification is complete. -
[ ] 6. Make sure that automatic system confirms that report has been added to the backlog.
@magento give me 2.4-develop instance
Hi @engcom-Bravo. Thank you for your request. I'm working on Magento instance for you.
Hi @engcom-Bravo, here is your Magento Instance: https://a1b45ae7b964d975cf10e2187d0cdb2b.instances.magento-community.engineering Admin access: https://a1b45ae7b964d975cf10e2187d0cdb2b.instances.magento-community.engineering/admin_481c Login: f0bdf4f7 Password: d3c37dec03e5
Hi @jayankaghosh,
Thank you for reporting and collaboration.
Verified the issue on Magento 2.4-develop branch but the issue is not reproducible.We are able to Update customer email with customer has 100+ orders with in a few seconds.Kindly refer the screenshots.


Please let us know we miss anything.
Thanks.
Hi @jayankaghosh,
We have noticed that this issue has not been updated for a period of 14 Days. Hence we assume that this issue is fixed now, so we are closing it. Please raise a fresh ticket or reopen this ticket if you need more assistance on this.
Thanks.
We have the same issue. Our b2b customers have lots of orders and for some it's not even possible to update anymore because it runs out of memory. Please fix this.
I've also ran into this issue with a customer having 639 orders. When trying to edit their email through the admin it would also run out of memory. Tested locally by adding return; to the top of \Magento\Customer\Observer\UpgradeOrderCustomerEmailObserver::execute
to prevent it from updating the orders. This then allowed me to save the customer
I've also ran into this issue with a customer having 639 orders. When trying to edit their email through the admin it would also run out of memory. Tested locally by adding return; to the top of
\Magento\Customer\Observer\UpgradeOrderCustomerEmailObserver::execute
to prevent it from updating the orders. This then allowed me to save the customer
Hi @mattiweb Can you please share the solution?
@ayushi011 I didn't fix the underlying issue but I disabled the functionality that updates all the customers orders with the new email by creating a custom module and inside the etc/events.xml I just disabled the event with the following. (more of a temp workaround)
<event name="customer_save_after_data_object">
<observer name="upgrade_order_customer_email" disabled="true"/>
</event>
You could also create an around plugin on \Magento\Customer\Observer\UpgradeOrderCustomerEmailObserver::execute
with custom logic to prevent it
If you still want the functionality you could try what jayankaghosh put in his original comment but I never got round to trying it