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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user