WordPress.org

Make WordPress Core

Changeset 21628


Ignore:
Timestamp:
08/27/12 16:22:45 (23 months ago)
Author:
ryan
Message:

Use switch_to_blog()/restore_current_blog() in get_blog_post() and get_blog_permalink(). Eliminate the duplicate caching in these functions. Return WP_Post from get_blog_post(). Update phpdoc. Remove global-posts cache invalidation. Props jondavidjohn fixes #21595

Location:
trunk/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/ms-functions.php

    r21413 r21628  
    153153 * @param int $blog_id ID of the blog. 
    154154 * @param int $post_id ID of the post you're looking for. 
    155  * @return object The post. 
     155 * @return WP_Post|null WP_Post on success or null on failure 
    156156 */ 
    157157function get_blog_post( $blog_id, $post_id ) { 
    158     global $wpdb; 
    159  
    160     $key = $blog_id . '-' . $post_id; 
    161     $post = wp_cache_get( $key, 'global-posts' ); 
    162     if ( $post == false ) { 
    163         $post = $wpdb->get_row( $wpdb->prepare( 'SELECT * FROM ' . $wpdb->get_blog_prefix( $blog_id ) . 'posts WHERE ID = %d', $post_id ) ); 
    164         wp_cache_add( $key, $post, 'global-posts' ); 
    165     } 
     158    switch_to_blog( $blog_id ); 
     159    $post = get_post( $post_id ); 
     160    restore_current_blog(); 
    166161 
    167162    return $post; 
     
    314309 * @since MU 1.0 
    315310 * 
    316  * @param int $_blog_id ID of the source blog. 
     311 * @param int $blog_id ID of the source blog. 
    317312 * @param int $post_id ID of the desired post. 
    318313 * @return string The post's permalink 
    319314 */ 
    320 function get_blog_permalink( $_blog_id, $post_id ) { 
    321     $key = "{$_blog_id}-{$post_id}-blog_permalink"; 
    322     $link = wp_cache_get( $key, 'site-options' ); 
    323     if ( $link == false ) { 
    324         switch_to_blog( $_blog_id ); 
    325         $link = get_permalink( $post_id ); 
    326         restore_current_blog(); 
    327         wp_cache_add( $key, $link, 'site-options', 360 ); 
    328     } 
     315function get_blog_permalink( $blog_id, $post_id ) { 
     316    switch_to_blog( $blog_id ); 
     317    $link = get_permalink( $post_id ); 
     318    restore_current_blog(); 
     319 
    329320    return $link; 
    330321} 
  • trunk/wp-includes/post.php

    r21601 r21628  
    45184518        } 
    45194519    } 
    4520  
    4521     if ( is_multisite() ) 
    4522         wp_cache_delete( $wpdb->blogid . '-' . $post->ID, 'global-posts' ); 
    45234520} 
    45244521 
Note: See TracChangeset for help on using the changeset viewer.