Make WordPress Core

Changeset 11241


Ignore:
Timestamp:
05/08/2009 06:04:13 PM (17 years ago)
Author:
ryan
Message:

Cache get_adjacent_post() queries for the duration of the page load to avoid running queries multiple times

File:
1 edited

Legend:

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

    r11218 r11241  
    869869        global $post, $wpdb;
    870870
    871         if( empty($post) || !is_single() || is_attachment() )
     871        if ( empty($post) || !is_single() || is_attachment() )
    872872                return null;
    873873
     
    906906        $sort  = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1" );
    907907
    908         return $wpdb->get_row("SELECT p.* FROM $wpdb->posts AS p $join $where $sort");
     908        $query = "SELECT p.* FROM $wpdb->posts AS p $join $where $sort";
     909        $query_key = 'adjacent_post_' . md5($query);
     910        $result = wp_cache_get($query_key, 'counts');
     911        if ( false !== $result )
     912                return $result;
     913
     914        $result = $wpdb->get_row("SELECT p.* FROM $wpdb->posts AS p $join $where $sort");
     915        wp_cache_set($query_key, $result, 'counts');
     916        return $result;
    909917}
    910918
Note: See TracChangeset for help on using the changeset viewer.