_prime_post_parent_id_caches( int[] $ids )
- Since
- 6.4.0
- Source
wp-includes/post.php:8527
Compatibility
- WordPress
- since 6.4.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$idsint[]- ID list.
Performance profile
How much work a call to _prime_post_parent_id_caches() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Scales with input
- Instructions
- 19–65
- Plugin surface
- None
- Called by
- 1
Reaches the database via ->get_results().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 84.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- cacheobject cache
wp_cache_get_multiple()called directly - sqldatabase query
->get_results()called directly
What one call costs · 4 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost _prime_post_parent_id_caches() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
empty($ids) | 19 | array_filter(), array_map(), array_unique() |
!empty($ids) && empty($non_cached_ids) | 35–37 | array_filter(), array_map(), array_unique(), array_values(), wp_cache_get_multiple() |
!empty($ids) && !empty($non_cached_ids) | 55–57 | array_filter(), array_map(), array_unique(), array_values(), wp_cache_get_multiple(), sprintf(), ->get_results() |
!empty($ids) && !empty($non_cached_ids) | 62–65 | array_filter(), array_map(), array_unique(), array_values(), wp_cache_get_multiple(), sprintf(), ->get_results(), wp_cache_add_multiple() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 84 | 19–65 | 10 | |
| 8.5 | 84 | 19–65 | 10 | |
| 8.4 | 84 | 19–65 | 10 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 87 | 19–68 | 10 | |
| 8.2 | 87 | 19–68 | 10 | |
| 8.1 | 87 | 19–68 | 10 | |
| 7.4 | 87 | 19–68 | 10 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 2
- wp_cache_get_multiple()Retrieves multiple values from the cache in one call.
- wp_cache_add_multiple()Adds multiple values to the cache in one call, if the cache keys don't already exist.
Used by · 1
- WP_Query::get_posts()Retrieves an array of posts based on query variables.
Source code
function _prime_post_parent_id_caches( array $ids ) { global $wpdb; $ids = array_filter( $ids, '_validate_cache_id' ); $ids = array_unique( array_map( 'intval', $ids ), SORT_NUMERIC ); if ( empty( $ids ) ) { return; } $cache_keys = array(); foreach ( $ids as $id ) { $cache_keys[ $id ] = 'post_parent:' . (string) $id; } $cached_data = wp_cache_get_multiple( array_values( $cache_keys ), 'posts' ); $non_cached_ids = array(); foreach ( $cache_keys as $id => $cache_key ) { if ( false === $cached_data[ $cache_key ] ) { $non_cached_ids[] = $id; } } if ( ! empty( $non_cached_ids ) ) { $fresh_posts = $wpdb->get_results( sprintf( "SELECT $wpdb->posts.ID, $wpdb->posts.post_parent FROM $wpdb->posts WHERE ID IN (%s)", implode( ',', $non_cached_ids ) ) ); if ( $fresh_posts ) { $post_parent_data = array(); foreach ( $fresh_posts as $fresh_post ) { $post_parent_data[ 'post_parent:' . (string) $fresh_post->ID ] = (int) $fresh_post->post_parent; } wp_cache_add_multiple( $post_parent_data, 'posts' ); } }}Changelog
Introduced in 6.4.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/post.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.