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
This commit is contained in:
Peter Wilson 2024-07-23 00:27:15 +00:00
parent 8529edd888
commit 2ecc281f69
2 changed files with 19 additions and 1 deletions

View File

@ -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;
}

View File

@ -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.