Options, Meta APIs: Avoid a race condition causing the first of two subsequent requests updating different options at the same time to lose changes.
Every time an autoloaded option is updated or deleted, the `alloptions` cache is similarly updated. Due to the race condition, on any autoloaded option being updated, every other autoloaded option had its value set to the value at load time, causing a mismatch between the data in the persistent cache and the database. This change introduces a `$force_cache` parameter for `wp_load_alloptions()` to force an update of the local `alloptions` cache from the persistent cache when an option is added, updated, or deleted, to minimize the chance of affecting other options. Props fabifott, rmccue, tollmanz, johnjamesjacoby, spacedmonkey, dd32, jipmoors, tellyworth, jeremyclarke, joehoyle, boonebgorges, danielbachhuber, flixos90, jeichorn, mihdan, Grzegorz.Janoszka, SergeyBiryukov. Merges [46753] and [46779] to the 5.3 branch. Fixes #31245. Built from https://develop.svn.wordpress.org/branches/5.3@46780 git-svn-id: http://core.svn.wordpress.org/branches/5.3@46580 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
c54903a12e
commit
50f419f0a8
|
@ -189,16 +189,19 @@ function form_option( $option ) {
|
|||
* Loads and caches all autoloaded options, if available or all options.
|
||||
*
|
||||
* @since 2.2.0
|
||||
* @since 5.3.1 The `$force_cache` parameter was added.
|
||||
*
|
||||
* @global wpdb $wpdb WordPress database abstraction object.
|
||||
*
|
||||
* @param bool $force_cache Optional. Whether to force an update of the local cache
|
||||
* from the persistent cache. Default false.
|
||||
* @return array List of all options.
|
||||
*/
|
||||
function wp_load_alloptions() {
|
||||
function wp_load_alloptions( $force_cache = false ) {
|
||||
global $wpdb;
|
||||
|
||||
if ( ! wp_installing() || ! is_multisite() ) {
|
||||
$alloptions = wp_cache_get( 'alloptions', 'options' );
|
||||
$alloptions = wp_cache_get( 'alloptions', 'options', $force_cache );
|
||||
} else {
|
||||
$alloptions = false;
|
||||
}
|
||||
|
@ -397,7 +400,7 @@ function update_option( $option, $value, $autoload = null ) {
|
|||
}
|
||||
|
||||
if ( ! wp_installing() ) {
|
||||
$alloptions = wp_load_alloptions();
|
||||
$alloptions = wp_load_alloptions( true );
|
||||
if ( isset( $alloptions[ $option ] ) ) {
|
||||
$alloptions[ $option ] = $serialized_value;
|
||||
wp_cache_set( 'alloptions', $alloptions, 'options' );
|
||||
|
@ -505,7 +508,7 @@ function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' )
|
|||
|
||||
if ( ! wp_installing() ) {
|
||||
if ( 'yes' == $autoload ) {
|
||||
$alloptions = wp_load_alloptions();
|
||||
$alloptions = wp_load_alloptions( true );
|
||||
$alloptions[ $option ] = $serialized_value;
|
||||
wp_cache_set( 'alloptions', $alloptions, 'options' );
|
||||
} else {
|
||||
|
@ -583,7 +586,7 @@ function delete_option( $option ) {
|
|||
$result = $wpdb->delete( $wpdb->options, array( 'option_name' => $option ) );
|
||||
if ( ! wp_installing() ) {
|
||||
if ( 'yes' == $row->autoload ) {
|
||||
$alloptions = wp_load_alloptions();
|
||||
$alloptions = wp_load_alloptions( true );
|
||||
if ( is_array( $alloptions ) && isset( $alloptions[ $option ] ) ) {
|
||||
unset( $alloptions[ $option ] );
|
||||
wp_cache_set( 'alloptions', $alloptions, 'options' );
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.3.1-alpha-46778';
|
||||
$wp_version = '5.3.1-alpha-46780';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue