magento_extension icon indicating copy to clipboard operation
magento_extension copied to clipboard

Customers API : Filter order collection by customer ID for performance cause

Open Dnd-Coch opened this issue 5 years ago • 1 comments

Filter by customer email on each request takes a long time on large order collection and creates performance issues (slow queries in database):

# Query_time: 2.330689 Lock_time: 0.000100 Rows_sent: 3 Rows_examined: 372888 SELECT main_table.* FROM sales_flat_order AS main_table WHERE (customer_email = '[email protected]');

It is much faster to filter by customer ID if customer exists, and filter by email only if required.

Dnd-Coch avatar Nov 30 '18 18:11 Dnd-Coch

I suggest to replace Mage::getModel('sales/order')->getCollection() by Mage::getResourceModel('sales/order_collection').

luigifab avatar Apr 09 '20 13:04 luigifab