plugin updates
This commit is contained in:
@@ -145,8 +145,35 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
||||
return boolval( $locked );
|
||||
}
|
||||
|
||||
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
||||
$result = $wpdb->query( $query );
|
||||
// The insert query can potentially result in a deadlock if there is high concurrency
|
||||
// when trying to insert products, which will result in a false negative for SKU lock
|
||||
// and incorrectly products not being created.
|
||||
// To mitigate this, we will retry the query 3 times before giving up.
|
||||
for ( $attempts = 0; $attempts < 3; $attempts++ ) {
|
||||
if ( $attempts > 1 ) {
|
||||
usleep( 10000 );
|
||||
}
|
||||
|
||||
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
||||
$result = $wpdb->query( $query );
|
||||
if ( false !== $result ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( false === $result ) {
|
||||
wc_get_logger()->warning(
|
||||
sprintf(
|
||||
'Failed to obtain SKU lock for product: ID "%d" with SKU "%s" after %d attempts.',
|
||||
$product_id,
|
||||
$sku,
|
||||
$attempts,
|
||||
),
|
||||
array(
|
||||
'error' => $wpdb->last_error,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return (bool) $result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user