commit 535e3f808f6b99a321fe914af393cc2d154580b1 Author: Damien Tournoud Date: Wed Dec 7 16:27:44 2011 +0100 Issue #1363826: workaround deadlock issues when saving orders concurrently. diff --git a/modules/order/commerce_order.install b/modules/order/commerce_order.install index 71b89a2..5e5a6e2 100644 --- a/modules/order/commerce_order.install +++ b/modules/order/commerce_order.install @@ -19,13 +19,13 @@ function commerce_order_schema() { 'description' => 'The order number displayed to the customer.', 'type' => 'varchar', 'length' => 255, - 'not null' => TRUE, + 'not null' => FALSE, ), 'revision_id' => array( 'description' => 'The current {commerce_order_revision}.revision_id version identifier.', 'type' => 'int', 'unsigned' => TRUE, - 'not null' => TRUE, + 'not null' => FALSE, 'default' => 0, ), 'type' => array( @@ -112,7 +112,7 @@ function commerce_order_schema() { 'description' => 'The order number displayed to the customer for this revision.', 'type' => 'varchar', 'length' => 255, - 'not null' => TRUE, + 'not null' => FALSE, ), 'revision_id' => array( 'description' => 'The primary identifier for this revision.', diff --git a/modules/order/includes/commerce_order.controller.inc b/modules/order/includes/commerce_order.controller.inc index d1cec78..a4cd94b 100644 --- a/modules/order/includes/commerce_order.controller.inc +++ b/modules/order/includes/commerce_order.controller.inc @@ -22,9 +22,9 @@ class CommerceOrderEntityController extends DrupalCommerceEntityController { */ public function create(array $values = array()) { $values += array( - 'order_id' => '', - 'order_number' => '', - 'revision_id' => '', + 'order_id' => NULL, + 'order_number' => NULL, + 'revision_id' => NULL, 'uid' => '', 'mail' => ( !empty($values['uid']) && ($account = user_load($values['uid'])) ) ? $account->mail : '', 'data' => array(), @@ -119,6 +119,19 @@ class CommerceOrderEntityController extends DrupalCommerceEntityController { // Call the default attachLoad() method. This will add fields and call // hook_commerce_order_load(). parent::attachLoad($queried_orders, $revision_id); + + // Pre-load all the line items of the orders in one go. + $line_item_ids = array(); + foreach ($queried_orders as $order_id => $order) { + foreach ($order->commerce_line_items as $langcode => $items) { + foreach ($items as $delta => $item) { + $line_item_ids[$item['line_item_id']] = TRUE; + } + } + } + if ($line_item_ids) { + entity_load('commerce_line_item', array_keys($line_item_ids)); + } } }