Commit 65b9184e authored by Erick Hitter's avatar Erick Hitter
Browse files

Rather than frequently delete events and cause InnoDB to optimize, move events "out of the way"

parent d4921c5e
......@@ -467,7 +467,12 @@ class Events_Store extends Singleton {
public function mark_job_record_completed( $job_id, $flush_cache = true ) {
global $wpdb;
$success = $wpdb->update( $this->get_table_name(), array( 'status' => self::STATUS_COMPLETED, ), array( 'ID' => $job_id, ) );
$updates = array(
'status' => self::STATUS_COMPLETED,
'instance' => wp_rand( 1000000, 999999999 ), // Breaks unique constraint, and can be recreated from entry's remaining data
);
$success = $wpdb->update( $this->get_table_name(), $updates, array( 'ID' => $job_id, ) );
// Delete internal cache
// Should only be skipped during bulk operations
......@@ -525,12 +530,8 @@ class Events_Store extends Singleton {
/**
* Stop discarding events, once again storing them in the table
*
* First clears any completed events to free unique timestamp-action-instance key
*/
public function resume_event_creation() {
$this->purge_completed_events();
$this->job_creation_suspended = false;
}
......
......@@ -35,7 +35,7 @@ class Internal_Events extends Singleton {
'callback' => 'clean_legacy_data',
),
array(
'schedule' => 'a8c_cron_control_minute',
'schedule' => 'hourly',
'action' => 'a8c_cron_control_purge_completed_events',
'callback' => 'purge_completed_events',
),
......
......@@ -235,7 +235,6 @@ class Events extends \WP_CLI_Command {
'event_args' => '',
);
// Provide relative next run only for events that have yet to run
if ( $event->status === \Automattic\WP\Cron_Control\Events_Store::STATUS_PENDING ) {
$row['next_run_relative'] = $this->calculate_interval( $event->timestamp - time() );
}
......@@ -244,12 +243,15 @@ class Events extends \WP_CLI_Command {
$row['event_args'] = maybe_serialize( $event->args );
// Human-readable version of next run
if ( \Automattic\WP\Cron_Control\Events_Store::STATUS_COMPLETED === $event->status ) {
$instance = md5( $row['event_args'] );
$row['instance'] = "{$instance} - {$row['instance']}";
}
if ( isset( $event->interval ) && $event->interval ) {
$row['recurrence'] = $this->calculate_interval( $event->interval );
}
// Named schedule
if ( isset( $event->schedule ) && $event->schedule ) {
$row['schedule_name'] = $event->schedule;
}
......
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