Commit 77c2e840 authored by Erick Hitter's avatar Erick Hitter Committed by GitHub
Browse files

Merge pull request #133 from Automattic/fix/104-cli-sorting

Allow sorting to be enforced when listing events, but default to unsorted
parents d9021f6e 32a33321
...@@ -374,8 +374,15 @@ class Events_Store extends Singleton { ...@@ -374,8 +374,15 @@ class Events_Store extends Singleton {
$offset = 0; $offset = 0;
} }
// Do not sort, otherwise index isn't used // Avoid sorting whenever possible, otherwise filesort is used
$jobs = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$this->get_table_name()} WHERE status = %s LIMIT %d,%d;", $args['status'], $offset, $args['quantity'] ), 'OBJECT' ); // Generally only necessary in CLI commands for pagination, as full list of events is usually required
if ( isset( $args['force_sort'] ) && true === $args['force_sort'] ) {
$query = $wpdb->prepare( "SELECT * FROM {$this->get_table_name()} WHERE status = %s ORDER BY timestamp ASC LIMIT %d,%d;", $args['status'], $offset, $args['quantity'] );
} else {
$query = $wpdb->prepare( "SELECT * FROM {$this->get_table_name()} WHERE status = %s LIMIT %d,%d;", $args['status'], $offset, $args['quantity'] );
}
$jobs = $wpdb->get_results( $query, 'OBJECT' );
if ( is_array( $jobs ) ) { if ( is_array( $jobs ) ) {
$jobs = array_map( array( $this, 'format_job' ), $jobs ); $jobs = array_map( array( $this, 'format_job' ), $jobs );
......
...@@ -191,9 +191,10 @@ class Events extends \WP_CLI_Command { ...@@ -191,9 +191,10 @@ class Events extends \WP_CLI_Command {
// Query // Query
$items = \Automattic\WP\Cron_Control\get_events( array( $items = \Automattic\WP\Cron_Control\get_events( array(
'status' => $event_status, 'status' => $event_status,
'quantity' => $limit, 'quantity' => $limit,
'page' => $page, 'page' => $page,
'force_sort' => true,
) ); ) );
// Bail if we don't get results // Bail if we don't get results
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment