[wp-trac] [WordPress Trac] #12302: add_metadata() Fails to Store Serialized Values as BINARY
WordPress Trac
noreply at wordpress.org
Mon Aug 9 04:29:25 UTC 2021
#12302: add_metadata() Fails to Store Serialized Values as BINARY
-------------------------------+----------------------
Reporter: miqrogroove | Owner: ryan
Type: defect (bug) | Status: closed
Priority: normal | Milestone:
Component: Database | Version: 3.0
Severity: normal | Resolution: wontfix
Keywords: needs-patch close | Focuses:
-------------------------------+----------------------
Comment (by leanice):
In the binary format, the user objects (e.g. Product object) are
serialized from the client end and stored on the server side in the same
form. Every time an item is requested from the server, the client receives
the binary form of the item which is then de-serialized to Product object
locally. Furthermore, serialization/deserialization takes place on the
client side only, and just once either while fetching or adding the data –
de-serialized while fetching and serialized while adding. This saves cost
of serialization/de-serialization, which is noticeable especially in cases
where sizeable data is added or fetched from the cache.
Binary Format is beneficial if most of your processing is on the client
side, and the operations performed are like add, update, fetch, and remove
from the cache. For example, a serialized Product object is fetched from
the cache to display its contents. Using binary format, the item will only
need to be de-serialized once it reaches the client, thus, keeping the
processing cost to a minimum. In case Object format is being used, the
server will serialize the Product object and send it to the client which
will then de-serialize it. This increases the overall overhead and cost of
serialization and de-serialization.
Similarly, if an object is being added to the cache using Binary format,
it will be serialized before it is sent over the network and it will be
stored as it is.
PHP add_metadata - examples found. These are the top rated real world PHP
examples of add_metadata extracted from open source projects. You can rate
examples to help us improve the quality of examples.
Programming Language: PHP
Method/Function: add_metadata
{{{
function update_metadata($meta_type, $object_id, $meta_key, $meta_value,
$prev_value = '')
{
if (!$meta_type || !$meta_key) {
return false;
}
if (!($table = _get_meta_table($meta_type))) {
return false;
}
global $wpdb;
$column = esc_sql($meta_type . '_id');
$id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id';
// expected_slashed ($meta_key)
$meta_key = stripslashes($meta_key);
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,
$meta_value);
}
$meta_value = maybe_serialize(stripslashes_deep($meta_value));
$data = compact('meta_value');
$where = array($column => $object_id, 'meta_key' => $meta_key);
if (!empty($prev_value)) {
$prev_value = maybe_serialize($prev_value);
$where['meta_value'] = $prev_value;
}
do_action("update_{$meta_type}_meta", $meta_id, $object_id, $meta_key,
$meta_value);
$wpdb->update($table, $data, $where);
wp_cache_delete($object_id, $meta_type . '_meta');
do_action("updated_{$meta_type}_meta", $meta_id, $object_id,
$meta_key, $meta_value);
return true;
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/12302#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list