Make WordPress Core


Ignore:
Timestamp:
01/21/2019 04:26:33 AM (8 years ago)
Author:
peterwilsoncc
Message:

Options: Avoid unnecessary DB calls when updating network options.

Adds a maybe_serialize() comparison for the old and new values in update_network_option() to avoid unnecessary database writes when options contain identical objects.

Props bor0.
Fixes #44956.

File:
1 edited

Legend:

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

    r44463 r44662  
    15841584        $value = apply_filters( "pre_update_site_option_{$option}", $value, $old_value, $option, $network_id );
    15851585
    1586         if ( $value === $old_value ) {
     1586        /*
     1587         * If the new and old values are the same, no need to update.
     1588         *
     1589         * Unserialized values will be adequate in most cases. If the unserialized
     1590         * data differs, the (maybe) serialized data is checked to avoid
     1591         * unnecessary database calls for otherwise identical object instances.
     1592         *
     1593         * See https://core.trac.wordpress.org/ticket/44956
     1594         */
     1595        if ( $value === $old_value || maybe_serialize( $value ) === maybe_serialize( $old_value ) ) {
    15871596                return false;
    15881597        }
Note: See TracChangeset for help on using the changeset viewer.