WordPress.org

Make WordPress Core

Changeset 21919


Ignore:
Timestamp:
09/19/12 18:11:43 (19 months ago)
Author:
ryan
Message:

Improve performance of query in get_adjacent_post(). Get the ID and then call get_post(). Props apokalyptik, nacin, javert03. fixes #18120

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/link-template.php

    r21802 r21919  
    11671167    $sort  = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1" ); 
    11681168 
    1169     $query = "SELECT p.* FROM $wpdb->posts AS p $join $where $sort"; 
     1169    $query = "SELECT p.id FROM $wpdb->posts AS p $join $where $sort"; 
    11701170    $query_key = 'adjacent_post_' . md5($query); 
    11711171    $result = wp_cache_get($query_key, 'counts'); 
    11721172    if ( false !== $result ) { 
    1173         if ( is_object( $result ) ) 
    1174             $result = new WP_Post( $result ); 
     1173        if ( $result ) 
     1174            $result = get_post( $result ); 
    11751175        return $result; 
    11761176    } 
    11771177 
    1178     $result = $wpdb->get_row("SELECT p.* FROM $wpdb->posts AS p $join $where $sort"); 
     1178    $result = $wpdb->get_var( $query ); 
    11791179    if ( null === $result ) 
    11801180        $result = ''; 
     
    11821182    wp_cache_set($query_key, $result, 'counts'); 
    11831183 
    1184     if ( is_object( $result ) ) 
    1185         $result = new WP_Post( $result ); 
     1184    if ( $result ) 
     1185        $result = get_post( $result ); 
    11861186 
    11871187    return $result; 
     
    20582058        $url = WP_PLUGIN_URL; 
    20592059 
    2060      
     2060 
    20612061    $url = set_url_scheme( $url ); 
    20622062 
Note: See TracChangeset for help on using the changeset viewer.