Make WordPress Core

Changeset 2421


Ignore:
Timestamp:
03/09/2005 03:16:30 AM (20 years ago)
Author:
ryan
Message:

Page caching fixes. Mosquito bugs 920, 927, and 934.

Location:
trunk/wp-includes
Files:
2 edited

Legend:

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

    r2418 r2421  
    998998    global $wpdb, $cache_pages;
    999999
     1000    $dates = ",UNIX_TIMESTAMP(post_modified) AS time_modified";
     1001    $dates .= ",UNIX_TIMESTAMP(post_date) AS time_created";
     1002
    10001003    if (!isset($cache_pages[$page_id])) {
    1001         $cache_pages[$page_id] = $wpdb->get_row("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE ID = '$page_id'");
     1004        $cache_pages[$page_id] = $wpdb->get_row("SELECT ID, post_title, post_name, post_parent $dates FROM $wpdb->posts WHERE ID = '$page_id'");
    10021005    }
    10031006
     
    10111014
    10121015    while ($page->post_parent != 0) {
    1013         $page = $wpdb->get_row("SELECT post_name, post_parent FROM $wpdb->posts WHERE ID = '$page->post_parent'");
     1016        if (isset($cache_pages[$page->post_parent])) {
     1017            $page = $cache_pages[$page->post_parent];
     1018        } else {
     1019            $page = $wpdb->get_row("SELECT ID, post_title, post_name, post_parent $dates FROM $wpdb->posts WHERE ID = '$page->post_parent'");
     1020            $cache_pages[$page->ID] = $page;
     1021        }
    10141022        $uri = urldecode($page->post_name) . "/" . $uri;
    10151023    }
  • trunk/wp-includes/template-functions-post.php

    r2420 r2421  
    265265    global $wpdb, $cache_pages;
    266266
    267     if (!isset($cache_pages) || empty($cache_pages)) {
    268 
    269         parse_str($args, $r);
    270 
    271         if (!isset($r['child_of'])) $r['child_of'] = 0;
    272         if (!isset($r['sort_column'])) $r['sort_column'] = 'post_title';
    273         if (!isset($r['sort_order'])) $r['sort_order'] = 'ASC';
    274 
    275         $exclusions = '';
    276         if (!empty($r['exclude'])) {
    277             $expages = preg_split('/[\s,]+/',$r['exclude']);
    278             if (count($expages)) {
    279                 foreach ($expages as $expage) {
    280                     $exclusions .= ' AND ID <> ' . intval($expage) . ' ';
    281                 }
     267    parse_str($args, $r);
     268
     269    if (!isset($r['child_of'])) $r['child_of'] = 0;
     270    if (!isset($r['sort_column'])) $r['sort_column'] = 'post_title';
     271    if (!isset($r['sort_order'])) $r['sort_order'] = 'ASC';
     272
     273    $exclusions = '';
     274    if (!empty($r['exclude'])) {
     275        $expages = preg_split('/[\s,]+/',$r['exclude']);
     276        if (count($expages)) {
     277            foreach ($expages as $expage) {
     278                $exclusions .= ' AND ID <> ' . intval($expage) . ' ';
    282279            }
    283280        }
    284 
    285         $dates = ",UNIX_TIMESTAMP(post_modified) AS time_modified";
    286         $dates .= ",UNIX_TIMESTAMP(post_date) AS time_created";
    287    
    288         $post_parent = '';
    289         if ($r['child_of']) {
    290             $post_parent = ' AND post_parent=' . $r['child_of'] . ' ';
    291         }
    292    
    293         $pages = $wpdb->get_results("SELECT " .
    294           "ID, post_title, post_name, post_parent " .
    295           "$dates " .
    296           "FROM $wpdb->posts " .
    297           "WHERE post_status = 'static' " .
    298           "$post_parent" .
    299           "$exclusions " .
    300           "ORDER BY " . $r['sort_column'] . " " . $r['sort_order']);
    301 
    302         $cache_pages = array();
    303         if (count($pages)) {
    304             foreach($pages as $page) {
    305                 $cache_pages[$page->ID] = $page;
    306             }
    307         }
    308     }
    309 
    310     return $cache_pages;
     281    }
     282
     283    $dates = ",UNIX_TIMESTAMP(post_modified) AS time_modified";
     284    $dates .= ",UNIX_TIMESTAMP(post_date) AS time_created";
     285   
     286    $post_parent = '';
     287    if ($r['child_of']) {
     288        $post_parent = ' AND post_parent=' . $r['child_of'] . ' ';
     289    }
     290   
     291    $pages = $wpdb->get_results("SELECT " .
     292                                                            "ID, post_title, post_name, post_parent " .
     293                                                            "$dates " .
     294                                                            "FROM $wpdb->posts " .
     295                                                            "WHERE post_status = 'static' " .
     296                                                            "$post_parent" .
     297                                                            "$exclusions " .
     298                                                            "ORDER BY " . $r['sort_column'] . " " . $r['sort_order']);
     299
     300    // Update page cache.
     301    if (count($pages)) {
     302        foreach($pages as $page) {
     303            $cache_pages[$page->ID] = $page;
     304        }
     305    }
     306
     307    if ( empty($pages) )
     308        $pages = array();
     309
     310    return $pages;
    311311}
    312312
Note: See TracChangeset for help on using the changeset viewer.