Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of is_installed check #374

Merged
merged 2 commits into from
Feb 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions includes/class-events-store.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ public static function is_installed(): bool {

// Can't rely on the DB_VERSION_OPTION here due to subsite copy/paste scenarios.
// Must truly check that the table is installed.
if ( wp_cache_get( 'is_installed', 'cron-control' ) ) {
return true;
$is_installed = wp_cache_get( 'is_installed', 'cron-control', false, $cache_exists );
if ( $cache_exists ) {
return $is_installed;
}

$table_name = $wpdb->prefix . self::TABLE_SUFFIX;
$is_installed = 1 === count( $wpdb->get_col( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table_name ) ) );
$is_installed = 1 === count( $wpdb->get_col( $wpdb->prepare( 'SELECT TABLE_NAME FROM information_schema.tables WHERE TABLE_NAME = %s', $table_name ) ) );

if ( $is_installed ) {
wp_cache_set( 'is_installed', true, 'cron-control' );
}
// Cache the results, will be overridden by _prepare_table() during installation.
wp_cache_add( 'is_installed', $is_installed, 'cron-control' );

return $is_installed;
}
Expand Down Expand Up @@ -147,10 +147,10 @@ protected function _prepare_table() {
dbDelta( $schema, true );

// Confirm that the table was created, and set the option to prevent further updates.
$table_count = count( $wpdb->get_col( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table_name ) ) );
$is_installed = 1 === count( $wpdb->get_col( $wpdb->prepare( 'SELECT TABLE_NAME FROM information_schema.tables WHERE TABLE_NAME = %s', $table_name ) ) );
WPprodigy marked this conversation as resolved.
Show resolved Hide resolved
wp_cache_set( 'is_installed', $is_installed, 'cron-control' );

if ( 1 === $table_count ) {
wp_cache_set( 'is_installed', true, 'cron-control' );
if ( $is_installed ) {
update_option( self::DB_VERSION_OPTION, self::DB_VERSION );
}

Expand Down
Loading