mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 12:20:22 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@39564 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -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 ) {
|
||||
|
||||
Reference in New Issue
Block a user