Skip to content

Commit

Permalink
Streamline WP_Background_Process::is_queued() and WP_Background_Proce…
Browse files Browse the repository at this point in the history
…ss::is_queue_empty()
  • Loading branch information
ianmjones committed Apr 18, 2023
1 parent f172c83 commit b6dd6b7
Showing 1 changed file with 2 additions and 28 deletions.
30 changes: 2 additions & 28 deletions classes/wp-background-process.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,7 @@ protected function resumed() {
* @return bool
*/
public function is_queued() {
$batch = $this->get_batch();

if ( empty( $batch ) ) {
return false;
}

return true;
return ! $this->is_queue_empty();
}

/**
Expand Down Expand Up @@ -349,27 +343,7 @@ public function maybe_handle() {
* @return bool
*/
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_' ) . '%';

$sql = '
SELECT COUNT(*)
FROM ' . $table . '
WHERE ' . $column . ' LIKE %s
';

$count = $wpdb->get_var( $wpdb->prepare( $sql, $key ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared

return ! ( $count > 0 );
return empty( $this->get_batch() );
}

/**
Expand Down

0 comments on commit b6dd6b7

Please sign in to comment.