From 2ecc281f69bf1cb34cdca762c18bc34f64a2f419 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Tue, 23 Jul 2024 00:27:15 +0000 Subject: [PATCH] Options, Meta APIs: Prime `notoptions` cache when deleting options. Prime the `notoptions` cache within `delete_option` and `delete_network_option` to avoid the need for a database query if `get_option` or `get_network_option` is subsequently called. Adds some associated tests to ensure that an option is cleared from the notoptions cache when an option is added either via `add_option`, `update_option` or their network option equivalent. Props pbearne, mukesh27. Fixes #61484. Built from https://develop.svn.wordpress.org/trunk@58782 git-svn-id: http://core.svn.wordpress.org/trunk@58184 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/option.php | 18 ++++++++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/wp-includes/option.php b/wp-includes/option.php index 4dee6ce118..125f25d40d 100644 --- a/wp-includes/option.php +++ b/wp-includes/option.php @@ -1217,6 +1217,15 @@ function delete_option( $option ) { } else { wp_cache_delete( $option, 'options' ); } + + $notoptions = wp_cache_get( 'notoptions', 'options' ); + + if ( ! is_array( $notoptions ) ) { + $notoptions = array(); + } + $notoptions[ $option ] = true; + + wp_cache_set( 'notoptions', $notoptions, 'options' ); } if ( $result ) { @@ -2284,6 +2293,15 @@ function delete_network_option( $network_id, $option ) { */ do_action( 'delete_site_option', $option, $network_id ); + $notoptions_key = "$network_id:notoptions"; + $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); + + if ( ! is_array( $notoptions ) ) { + $notoptions = array(); + } + $notoptions[ $option ] = true; + wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); + return true; } diff --git a/wp-includes/version.php b/wp-includes/version.php index 8fb2a9af2a..5d89d646c3 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.7-alpha-58781'; +$wp_version = '6.7-alpha-58782'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.