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:
parent
57681dda7a
commit
cd250fa7df
|
@ -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 );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue