From c950dcc6e3b1db8bf24cfda42ec9d5c5ba87de5d Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Thu, 7 Dec 2017 13:01:05 +0000 Subject: [PATCH] Background processing; multisite should process current blog queue only #17915 --- includes/libraries/wp-background-process.php | 59 +++++++++----------- 1 file changed, 26 insertions(+), 33 deletions(-) diff --git a/includes/libraries/wp-background-process.php b/includes/libraries/wp-background-process.php index 8ef9006bff7..9b5aeea74c8 100644 --- a/includes/libraries/wp-background-process.php +++ b/includes/libraries/wp-background-process.php @@ -184,21 +184,17 @@ abstract class WP_Background_Process extends WP_Async_Request { protected function is_queue_empty() { global $wpdb; - $table = $wpdb->options; - $column = 'option_name'; - - if ( is_multisite() ) { - $table = $wpdb->sitemeta; - $column = 'meta_key'; - } - $key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%'; - $count = $wpdb->get_var( $wpdb->prepare( " - SELECT COUNT(*) - FROM {$table} - WHERE {$column} LIKE %s - ", $key ) ); + if ( is_multisite() ) { + $count = $wpdb->get_var( $wpdb->prepare( " + SELECT COUNT(*) FROM {$wpdb->sitemeta} WHERE meta_key LIKE %s AND site_id = %d + ", $key, get_current_blog_id() ) ); + } else { + $count = $wpdb->get_var( $wpdb->prepare( " + SELECT COUNT(*) FROM {$wpdb->options} WHERE option_name LIKE %s + ", $key ) ); + } return ( $count > 0 ) ? false : true; } @@ -248,34 +244,31 @@ abstract class WP_Background_Process extends WP_Async_Request { } /** - * Get batch + * Get batch. * * @return stdClass Return the first batch from the queue */ protected function get_batch() { global $wpdb; - $table = $wpdb->options; - $column = 'option_name'; - $key_column = 'option_id'; - $value_column = 'option_value'; - - if ( is_multisite() ) { - $table = $wpdb->sitemeta; - $column = 'meta_key'; - $key_column = 'meta_id'; - $value_column = 'meta_value'; - } - $key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%'; - $query = $wpdb->get_row( $wpdb->prepare( " - SELECT * - FROM {$table} - WHERE {$column} LIKE %s - ORDER BY {$key_column} ASC - LIMIT 1 - ", $key ) ); + if ( is_multisite() ) { + $value_column = 'meta_value'; + $query = $wpdb->get_row( $wpdb->prepare( " + SELECT * FROM {$wpdb->sitemeta} + WHERE meta_key LIKE %s + AND site_id = %d + ORDER BY meta_id ASC LIMIT 1 + ", $key, get_current_blog_id() ) ); + } else { + $value_column = 'option_value'; + $query = $wpdb->get_row( $wpdb->prepare( " + SELECT * FROM {$wpdb->options} + WHERE option_name LIKE %s + ORDER BY option_id ASC LIMIT 1 + ", $key ) ); + } $batch = new stdClass(); $batch->key = $query->$column;