From 9f0cb87b3514563d1e9831a43216f97b6c9851df Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 28 Sep 2022 13:42:12 +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. git-svn-id: https://develop.svn.wordpress.org/trunk@54345 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/option.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/wp-includes/option.php b/src/wp-includes/option.php index 3c0b5b4cf9..fa2a9a5b01 100644 --- a/src/wp-includes/option.php +++ b/src/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.