Monitor only memory limit while running the data migration
Turns out WP_Background_Process uses an arbitrary value of 20 seconds of wall clock time to measure PHP "time limit" (b0617a13c4/includes/libraries/wp-background-process.php (L385)
) instead of cpu time which apparently it is not easy to measure in PHP. Since system calls (like database calls) are not included in the PHP maximum execution time, 20 seconds of wall clock is often way less than PHP time limit.
Thus, this commit removes the call to WP_Background_Process::time_exceeded() while running the function to migrate the post meta _customer_user to the field post_author. If the script times out, WP_Background_Process will restart it.
This commit is contained in:
parent
e02f3fbec4
commit
923eeb2e43
|
@ -139,7 +139,7 @@ class WC_Background_Updater extends WC_Background_Process {
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_batch_limit_exceeded() {
|
||||
return $this->batch_limit_exceeded();
|
||||
public function is_memory_exceeded() {
|
||||
return $this->memory_exceeded();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1723,7 +1723,7 @@ function wc_update_350_order_customer_id( $updater = false ) {
|
|||
|
||||
$wpdb->update( $wpdb->posts, array( 'post_author' => 0 ), array( 'post_type' => 'shop_order_refund' ) );
|
||||
} else {
|
||||
// If running the update from the wp-admin, copy data in batches being careful not to use more memory than allowed and respecting PHP time limit.
|
||||
// If running the update from the wp-admin, copy data in batches being careful not to use more memory than allowed.
|
||||
$admin_orders_sql = '';
|
||||
|
||||
// Get the list of orders that we don't want to change as they belong to user ID 1.
|
||||
|
@ -1771,8 +1771,8 @@ function wc_update_350_order_customer_id( $updater = false ) {
|
|||
|
||||
// Update post_author for a batch of orders.
|
||||
foreach ( $orders_meta_data as $order_meta ) {
|
||||
// Stop update execution and re-enqueue it if near memory and timeout limits.
|
||||
if ( $updater instanceof WC_Background_Updater && $updater->is_batch_limit_exceeded() ) {
|
||||
// Stop update execution and re-enqueue it if near memory limit.
|
||||
if ( $updater instanceof WC_Background_Updater && $updater->is_memory_exceeded() ) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1782,8 +1782,8 @@ function wc_update_350_order_customer_id( $updater = false ) {
|
|||
|
||||
// Set post_author to 0 instead of 1 on all shop_order_refunds.
|
||||
while ( true ) {
|
||||
// Stop update execution and re-enqueue it if near memory and timeout limits.
|
||||
if ( $updater instanceof WC_Background_Updater && $updater->is_batch_limit_exceeded() ) {
|
||||
// Stop update execution and re-enqueue it if near memory limit.
|
||||
if ( $updater instanceof WC_Background_Updater && $updater->is_memory_exceeded() ) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue