From bb8988e3ec92528c7395dd90e636dec87aaaf307 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 28 Sep 2022 13:44:15 +0000 Subject: [PATCH] Options, Meta APIs: Prevent excessive `notoptions` key lookups. When the `notoptions` key does not exist in a persistent object cache, it was requested hundreds of times until the first not-option is written. This commit improves performance by setting the value to an empty array to prevent non-existent `notoptions` key from triggering multiple key lookups. Follow-up to [4855], [14515]. Props tillkruess, dd32, spacedmonkey. Fixes #56639. Built from https://develop.svn.wordpress.org/trunk@54345 git-svn-id: http://core.svn.wordpress.org/trunk@53904 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/option.php | 6 ++++++ wp-includes/version.php | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/wp-includes/option.php b/wp-includes/option.php index 3c0b5b4cf9..fa2a9a5b01 100644 --- a/wp-includes/option.php +++ b/wp-includes/option.php @@ -164,6 +164,12 @@ function get_option( $option, $default = false ) { // Prevent non-existent options from triggering multiple queries. $notoptions = wp_cache_get( 'notoptions', 'options' ); + // Prevent non-existent `notoptions` key from triggering multiple key lookups. + if ( ! is_array( $notoptions ) ) { + $notoptions = array(); + wp_cache_set( 'notoptions', $notoptions, 'options' ); + } + if ( isset( $notoptions[ $option ] ) ) { /** * Filters the default value for an option. diff --git a/wp-includes/version.php b/wp-includes/version.php index 2ada9ec0e6..95a180fe8d 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.1-beta2-54344'; +$wp_version = '6.1-beta2-54345'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.