Make WordPress Core

Changeset 2479


Ignore:
Timestamp:
03/27/2005 09:56:10 PM (20 years ago)
Author:
ryan
Message:

Split post and page caches.

Location:
trunk/wp-includes
Files:
2 edited

Legend:

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

    r2478 r2479  
    576576}
    577577
     578// Retrieves page data given a page ID or page object.
     579// Handles page caching.
     580function &get_page(&$page, $output = OBJECT) {
     581    global $page_cache, $wpdb;
     582
     583    if ( empty($page) ) {
     584        if ( isset($GLOBALS['page']) )
     585            $page = & $GLOBALS['page'];
     586        else
     587            $page = null;
     588    } elseif (is_object($page) ) {
     589        if (! isset($page_cache[$page->ID]))
     590            $page_cache[$page->ID] = &$page;
     591        $page = & $page_cache[$page->ID];
     592    } else {
     593        if ( isset($GLOBALS['page']) && ($page == $GLOBALS['page']->ID) )
     594            $page = & $GLOBALS['page'];
     595        elseif (isset($page_cache[$page]))
     596            $page = & $page_cache[$page];
     597        else {
     598            $query = "SELECT * FROM $wpdb->posts WHERE ID=$page";
     599            $page_cache[$page] = & $wpdb->get_row($query);
     600            $page = & $page_cache[$page];
     601        }
     602    }
     603
     604    if ( $output == OBJECT ) {
     605        return $page;
     606    } elseif ( $output == ARRAY_A ) {
     607        return get_object_vars($page);
     608    } elseif ( $output == ARRAY_N ) {
     609        return array_values(get_object_vars($page));
     610    } else {
     611        return $page;
     612    }
     613}
     614
    578615// Retrieves category data given a category ID or category object.
    579616// The category cache is fully populated by the blog header, so we don't
     
    10471084
    10481085function get_page_uri($page_id) {
    1049     $page = get_post($page_id);
     1086    $page = get_page($page_id);
    10501087    $uri = urldecode($page->post_name);
    10511088
     
    10561093   
    10571094    while ($page->post_parent != 0) {
    1058         $page = get_post($page->post_parent);
     1095        $page = get_page($page->post_parent);
    10591096        $uri = urldecode($page->post_name) . "/" . $uri;
    10601097    }
     
    11001137    for ($i = 0; $i < count($posts); $i++) {
    11011138        $post_cache[$posts[$i]->ID] = &$posts[$i];
     1139    }
     1140}
     1141
     1142function update_page_cache(&$pages) {
     1143    global $page_cache;
     1144
     1145    if ( !$pages )
     1146        return;
     1147
     1148    for ($i = 0; $i < count($pages); $i++) {
     1149        $page_cache[$pages[$i]->ID] = &$pages[$i];
    11021150    }
    11031151}
  • trunk/wp-includes/template-functions-post.php

    r2478 r2479  
    252252
    253253function &get_pages($args = '') {
    254     global $wpdb, $cache_pages;
     254    global $wpdb, $page_cache;
    255255
    256256    parse_str($args, $r);
     
    282282                                                            "ORDER BY " . $r['sort_column'] . " " . $r['sort_order']);
    283283
     284    if ( empty($pages) )
     285        return array();
     286
    284287    // Update cache.
    285     update_post_cache($pages);
    286 
    287     if ( empty($pages) )
    288         $pages = array();
     288    update_page_cache($pages);
    289289
    290290    return $pages;
Note: See TracChangeset for help on using the changeset viewer.