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.


Built from https://develop.svn.wordpress.org/trunk@44662


git-svn-id: http://core.svn.wordpress.org/trunk@44493 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Peter Wilson 2019-01-21 04:27:51 +00:00
parent 989a28b482
commit 54d43d88ea
2 changed files with 11 additions and 2 deletions

View File

@ -1583,7 +1583,16 @@ function update_network_option( $network_id, $option, $value ) {
*/ */
$value = apply_filters( "pre_update_site_option_{$option}", $value, $old_value, $option, $network_id ); $value = apply_filters( "pre_update_site_option_{$option}", $value, $old_value, $option, $network_id );
if ( $value === $old_value ) { /*
* If the new and old values are the same, no need to update.
*
* Unserialized values will be adequate in most cases. If the unserialized
* data differs, the (maybe) serialized data is checked to avoid
* unnecessary database calls for otherwise identical object instances.
*
* See https://core.trac.wordpress.org/ticket/44956
*/
if ( $value === $old_value || maybe_serialize( $value ) === maybe_serialize( $old_value ) ) {
return false; return false;
} }

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.1-beta1-44661'; $wp_version = '5.1-beta1-44662';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.