get_page() logic re-ordering and inline comments

git-svn-id: https://develop.svn.wordpress.org/trunk@4625 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Mark Jaquith 2006-12-07 03:10:47 +00:00
parent 9271589a5a
commit 7c07cdc944
1 changed files with 21 additions and 13 deletions

View File

@ -928,6 +928,7 @@ function &get_page(&$page, $output = OBJECT) {
$_page = & $GLOBALS['page']; $_page = & $GLOBALS['page'];
wp_cache_add($_page->ID, $_page, 'pages'); wp_cache_add($_page->ID, $_page, 'pages');
} else { } else {
// shouldn't we just return NULL at this point? ~ Mark
$_page = null; $_page = null;
} }
} elseif ( is_object($page) ) { } elseif ( is_object($page) ) {
@ -936,22 +937,29 @@ function &get_page(&$page, $output = OBJECT) {
wp_cache_add($page->ID, $page, 'pages'); wp_cache_add($page->ID, $page, 'pages');
$_page = $page; $_page = $page;
} else { } else {
if ( isset($GLOBALS['page']->ID) && ($page == $GLOBALS['page']->ID) ) { // first, check the cache
$_page = & $GLOBALS['page']; if ( ! ( $_page = wp_cache_get($page, 'pages') ) ) {
wp_cache_add($_page->ID, $_page, 'pages'); // not in the page cache?
} elseif ( isset($GLOBALS['post_cache'][$blog_id][$page]) ) { if ( isset($GLOBALS['page']->ID) && ($page == $GLOBALS['page']->ID) ) { // for is_page() views
return get_post($page, $output); // I don't think this code ever gets executed ~ Mark
} elseif ( $_page = wp_cache_get($page, 'pages') ) { $_page = & $GLOBALS['page'];
// Got it. wp_cache_add($_page->ID, $_page, 'pages');
} else { } elseif ( isset($GLOBALS['post_cache'][$blog_id][$page]) ) { // it's actually a page, and is cached
$query = "SELECT * FROM $wpdb->posts WHERE ID= '$page' LIMIT 1"; return get_post($page, $output);
$_page = & $wpdb->get_row($query); } else { // it's not in any caches, so off to the DB we go
if ( 'post' == $_page->post_type ) // Why are we using assignment for this query?
return get_post($_page, $output); $_page = & $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID= '$page' LIMIT 1");
wp_cache_add($_page->ID, $_page, 'pages'); if ( 'post' == $_page->post_type )
return get_post($_page, $output);
// Potential issue: we're not checking to see if the post_type = 'page'
// So all non-'post' posts will get cached as pages.
wp_cache_add($_page->ID, $_page, 'pages');
}
} }
} }
// at this point, one way or another, $_post contains the page object
if ( $output == OBJECT ) { if ( $output == OBJECT ) {
return $_page; return $_page;
} elseif ( $output == ARRAY_A ) { } elseif ( $output == ARRAY_A ) {