From c21907ca1e51af9020871c162771cbc110bc0740 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Sun, 11 Dec 2016 21:43:43 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@39564 git-svn-id: http://core.svn.wordpress.org/trunk@39504 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/option.php | 13 +++++++++++-- wp-includes/version.php | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/wp-includes/option.php b/wp-includes/option.php index ac17c2f501..66fb6e4fd1 100644 --- a/wp-includes/option.php +++ b/wp-includes/option.php @@ -295,9 +295,18 @@ function update_option( $option, $value, $autoload = null ) { */ $value = apply_filters( 'pre_update_option', $value, $option, $old_value ); - // If the new and old values are the same, no need to update. - 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/38903 + */ + if ( $value === $old_value || maybe_serialize( $value ) === maybe_serialize( $old_value ) ) { return false; + } /** This filter is documented in wp-includes/option.php */ if ( apply_filters( 'default_option_' . $option, false, $option, false ) === $old_value ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index 4952d2d05e..0506979ce9 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.8-alpha-39563'; +$wp_version = '4.8-alpha-39564'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.