get_page() logic re-ordering and inline comments

git-svn-id: http://svn.automattic.com/wordpress/trunk@4625 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
markjaquith 2006-12-07 03:10:47 +00:00
parent 1b9c2ead05
commit 010379dd52
1 changed files with 21 additions and 13 deletions

View File

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