From de40ab4d12a90b450f1bfd7edf5fa3b1d93deb8c Mon Sep 17 00:00:00 2001 From: Thorsten Frommen Date: Tue, 1 Dec 2020 17:05:35 +0100 Subject: [PATCH 1/4] Remove the nextrun index --- inc/namespace.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/inc/namespace.php b/inc/namespace.php index 7f0fa6b..3288229 100644 --- a/inc/namespace.php +++ b/inc/namespace.php @@ -94,8 +94,7 @@ function create_tables() { PRIMARY KEY (`id`), KEY `status` (`status`), KEY `site` (`site`), - KEY `hook` (`hook`), - KEY `nextrun` (`nextrun`) + KEY `hook` (`hook`) ) ENGINE=InnoDB {$charset_collate};\n"; // TODO: check return value From 4f42b5d433fc9308750e6843367c63073edaee80 Mon Sep 17 00:00:00 2001 From: Thorsten Frommen Date: Tue, 1 Dec 2020 17:10:58 +0100 Subject: [PATCH 2/4] Add upgrade routine --- inc/upgrade/namespace.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/inc/upgrade/namespace.php b/inc/upgrade/namespace.php index e0ee7f3..28a6609 100644 --- a/inc/upgrade/namespace.php +++ b/inc/upgrade/namespace.php @@ -33,6 +33,10 @@ function upgrade_database() { upgrade_database_3(); } + if ( $database_version < 4 ) { + upgrade_database_4(); + } + update_site_option( 'cavalcade_db_version', DATABASE_VERSION ); Job::flush_query_cache(); @@ -83,3 +87,17 @@ function upgrade_database_3() { $wpdb->query( $query ); } + +/** + * Upgrade Cavalcade database tables to version 4. + * + * Remove nextrun index as it negatively affects performance. + */ +function upgrade_database_4() { + global $wpdb; + + $query = "ALTER TABLE `{$wpdb->base_prefix}cavalcade_jobs` + DROP INDEX `nextrun`"; + + $wpdb->query( $query ); +} From 0f3f346afba65e7bde42b08d105bd9f4709df072 Mon Sep 17 00:00:00 2001 From: Thorsten Frommen Date: Tue, 1 Dec 2020 17:11:26 +0100 Subject: [PATCH 3/4] Update database version --- plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.php b/plugin.php index 4f9efb0..7ebf88c 100644 --- a/plugin.php +++ b/plugin.php @@ -12,7 +12,7 @@ namespace HM\Cavalcade\Plugin; const DATE_FORMAT = 'Y-m-d H:i:s'; -const DATABASE_VERSION = 3; +const DATABASE_VERSION = 4; require __DIR__ . '/inc/namespace.php'; require __DIR__ . '/inc/class-job.php'; From e5d9e9c3368f9f2ee03d1057aa4fd4441c545fe2 Mon Sep 17 00:00:00 2001 From: Robert O'Rourke Date: Wed, 2 Dec 2020 16:34:14 +0000 Subject: [PATCH 4/4] Remove the `nextrun` index from the v3 update --- inc/upgrade/namespace.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/inc/upgrade/namespace.php b/inc/upgrade/namespace.php index 28a6609..853e97e 100644 --- a/inc/upgrade/namespace.php +++ b/inc/upgrade/namespace.php @@ -82,8 +82,7 @@ function upgrade_database_3() { $query = "ALTER TABLE `{$wpdb->base_prefix}cavalcade_jobs` ADD INDEX `site` (`site`), - ADD INDEX `hook` (`hook`), - ADD INDEX `nextrun` (`nextrun`)"; + ADD INDEX `hook` (`hook`)"; $wpdb->query( $query ); }