Defer the meta_id-fetching query until after comparison of the previous value, so that redundant calls to update_metadata() can bail without making that query. props nacin. fixes #22191

git-svn-id: http://core.svn.wordpress.org/trunk@22231 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Mark Jaquith 2012-10-15 05:51:38 +00:00
parent 57681dda7a
commit cd250fa7df
1 changed files with 3 additions and 3 deletions

View File

@ -123,9 +123,6 @@ function update_metadata($meta_type, $object_id, $meta_key, $meta_value, $prev_v
if ( null !== $check ) if ( null !== $check )
return (bool) $check; return (bool) $check;
if ( ! $meta_id = $wpdb->get_var( $wpdb->prepare( "SELECT $id_column FROM $table WHERE meta_key = %s AND $column = %d", $meta_key, $object_id ) ) )
return add_metadata($meta_type, $object_id, $meta_key, $passed_value);
// Compare existing value to new value if no prev value given and the key exists only once. // Compare existing value to new value if no prev value given and the key exists only once.
if ( empty($prev_value) ) { if ( empty($prev_value) ) {
$old_value = get_metadata($meta_type, $object_id, $meta_key); $old_value = get_metadata($meta_type, $object_id, $meta_key);
@ -135,6 +132,9 @@ function update_metadata($meta_type, $object_id, $meta_key, $meta_value, $prev_v
} }
} }
if ( ! $meta_id = $wpdb->get_var( $wpdb->prepare( "SELECT $id_column FROM $table WHERE meta_key = %s AND $column = %d", $meta_key, $object_id ) ) )
return add_metadata($meta_type, $object_id, $meta_key, $passed_value);
$_meta_value = $meta_value; $_meta_value = $meta_value;
$meta_value = maybe_serialize( $meta_value ); $meta_value = maybe_serialize( $meta_value );