From 54d43d88ea5895813fac6045d0f2bbc55d4d389e Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Mon, 21 Jan 2019 04:27:51 +0000 Subject: [PATCH] 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 --- wp-includes/option.php | 11 ++++++++++- wp-includes/version.php | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/wp-includes/option.php b/wp-includes/option.php index 1c0d88225e..21a09bbd51 100644 --- a/wp-includes/option.php +++ b/wp-includes/option.php @@ -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 ); - 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; } diff --git a/wp-includes/version.php b/wp-includes/version.php index 470a5044df..7fb21fcb56 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @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.