Make WordPress Core

Changeset 46780 for branches/5.3


Ignore:
Timestamp:
11/25/2019 01:44:16 PM (5 years ago)
Author:
SergeyBiryukov
Message:

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.

Location:
branches/5.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.3

  • branches/5.3/src/wp-includes/option.php

    r46121 r46780  
    190190 *
    191191 * @since 2.2.0
     192 * @since 5.3.1 The `$force_cache` parameter was added.
    192193 *
    193194 * @global wpdb $wpdb WordPress database abstraction object.
    194195 *
     196 * @param bool $force_cache Optional. Whether to force an update of the local cache
     197 *                          from the persistent cache. Default false.
    195198 * @return array List of all options.
    196199 */
    197 function wp_load_alloptions() {
     200function wp_load_alloptions( $force_cache = false ) {
    198201    global $wpdb;
    199202
    200203    if ( ! wp_installing() || ! is_multisite() ) {
    201         $alloptions = wp_cache_get( 'alloptions', 'options' );
     204        $alloptions = wp_cache_get( 'alloptions', 'options', $force_cache );
    202205    } else {
    203206        $alloptions = false;
     
    398401
    399402    if ( ! wp_installing() ) {
    400         $alloptions = wp_load_alloptions();
     403        $alloptions = wp_load_alloptions( true );
    401404        if ( isset( $alloptions[ $option ] ) ) {
    402405            $alloptions[ $option ] = $serialized_value;
     
    506509    if ( ! wp_installing() ) {
    507510        if ( 'yes' == $autoload ) {
    508             $alloptions            = wp_load_alloptions();
     511            $alloptions            = wp_load_alloptions( true );
    509512            $alloptions[ $option ] = $serialized_value;
    510513            wp_cache_set( 'alloptions', $alloptions, 'options' );
     
    584587    if ( ! wp_installing() ) {
    585588        if ( 'yes' == $row->autoload ) {
    586             $alloptions = wp_load_alloptions();
     589            $alloptions = wp_load_alloptions( true );
    587590            if ( is_array( $alloptions ) && isset( $alloptions[ $option ] ) ) {
    588591                unset( $alloptions[ $option ] );
Note: See TracChangeset for help on using the changeset viewer.