WordPress.org

Make WordPress Core


Ignore:
Timestamp:
12/11/2016 09:42:12 PM (4 years ago)
Author:
peterwilsoncc
Message:

Options: Prevent unnecessary SQL updates by update_option.

Previously an option containing an object would trigger an SQL UPDATE on all calls to update_option, even if the old and new values were identical. This was due to the old and new values having differing resource IDs.

This change compares the old and new values as serialized data to remove the resource ID from the comparison.

Props salcode, bradyvercher, peterwilsoncc.
Fixes #38903.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/option.php

    r39470 r39564  
    296296    $value = apply_filters( 'pre_update_option', $value, $option, $old_value );
    297297
    298     // If the new and old values are the same, no need to update.
    299     if ( $value === $old_value )
     298    /*
     299     * If the new and old values are the same, no need to update.
     300     *
     301     * Unserialized values will be adequate in most cases. If the unserialized
     302     * data differs, the (maybe) serialized data is checked to avoid
     303     * unnecessary database calls for otherwise identical object instances.
     304     *
     305     * See https://core.trac.wordpress.org/ticket/38903
     306     */
     307    if ( $value === $old_value || maybe_serialize( $value ) === maybe_serialize( $old_value ) ) {
    300308        return false;
     309    }
    301310
    302311    /** This filter is documented in wp-includes/option.php */
Note: See TracChangeset for help on using the changeset viewer.