From 2ea0626e5decce929149853dbc5c7afc036a7d42 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Mon, 27 Aug 2012 16:22:45 +0000 Subject: [PATCH] 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 git-svn-id: http://core.svn.wordpress.org/trunk@21628 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/ms-functions.php | 29 ++++++++++------------------- wp-includes/post.php | 3 --- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/wp-includes/ms-functions.php b/wp-includes/ms-functions.php index 202c3ab239..918465c541 100644 --- a/wp-includes/ms-functions.php +++ b/wp-includes/ms-functions.php @@ -152,17 +152,12 @@ function get_blog_count( $id = 0 ) { * * @param int $blog_id ID of the blog. * @param int $post_id ID of the post you're looking for. - * @return object The post. + * @return WP_Post|null WP_Post on success or null on failure */ function get_blog_post( $blog_id, $post_id ) { - global $wpdb; - - $key = $blog_id . '-' . $post_id; - $post = wp_cache_get( $key, 'global-posts' ); - if ( $post == false ) { - $post = $wpdb->get_row( $wpdb->prepare( 'SELECT * FROM ' . $wpdb->get_blog_prefix( $blog_id ) . 'posts WHERE ID = %d', $post_id ) ); - wp_cache_add( $key, $post, 'global-posts' ); - } + switch_to_blog( $blog_id ); + $post = get_post( $post_id ); + restore_current_blog(); return $post; } @@ -313,19 +308,15 @@ function create_empty_blog( $domain, $path, $weblog_title, $site_id = 1 ) { * * @since MU 1.0 * - * @param int $_blog_id ID of the source blog. + * @param int $blog_id ID of the source blog. * @param int $post_id ID of the desired post. * @return string The post's permalink */ -function get_blog_permalink( $_blog_id, $post_id ) { - $key = "{$_blog_id}-{$post_id}-blog_permalink"; - $link = wp_cache_get( $key, 'site-options' ); - if ( $link == false ) { - switch_to_blog( $_blog_id ); - $link = get_permalink( $post_id ); - restore_current_blog(); - wp_cache_add( $key, $link, 'site-options', 360 ); - } +function get_blog_permalink( $blog_id, $post_id ) { + switch_to_blog( $blog_id ); + $link = get_permalink( $post_id ); + restore_current_blog(); + return $link; } diff --git a/wp-includes/post.php b/wp-includes/post.php index 29ee906b33..94c410589d 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -4517,9 +4517,6 @@ function clean_post_cache( $post ) { clean_post_cache( $child ); } } - - if ( is_multisite() ) - wp_cache_delete( $wpdb->blogid . '-' . $post->ID, 'global-posts' ); } /**