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: https://develop.svn.wordpress.org/trunk@22231 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Mark Jaquith 2012-10-15 05:51:38 +00:00
parent c29cae6fd4
commit b7b4a12cfd
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 )
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.
if ( empty($prev_value) ) {
$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 = maybe_serialize( $meta_value );