WordPress.org

Make WordPress Core

Changeset 15585


Ignore:
Timestamp:
09/07/10 04:22:56 (7 years ago)
Author:
markjaquith
Message:

More efficient calendar queries. fixes #8351. props vladimir_kolesnikov

File:
1 edited

Legend:

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

    r15564 r15585  
    11151115 
    11161116    $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear); 
     1117    $last_day = date('t', $unixmonth); 
    11171118 
    11181119    // Get the next and previous month and year with at least one post 
    1119     $previous = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year 
     1120    $previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year 
    11201121        FROM $wpdb->posts 
    11211122        WHERE post_date < '$thisyear-$thismonth-01' 
     
    11231124            ORDER BY post_date DESC 
    11241125            LIMIT 1"); 
    1125     $next = $wpdb->get_row("SELECT  DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year 
     1126    $next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year 
    11261127        FROM $wpdb->posts 
    1127         WHERE post_date >   '$thisyear-$thismonth-01' 
    1128         AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' ) 
     1128        WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59' 
    11291129        AND post_type = 'post' AND post_status = 'publish' 
    1130             ORDER   BY post_date ASC 
     1130            ORDER BY post_date ASC 
    11311131            LIMIT 1"); 
    11321132 
     
    11801180    // Get days with posts 
    11811181    $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date) 
    1182         FROM $wpdb->posts WHERE MONTH(post_date) = '$thismonth' 
    1183         AND YEAR(post_date) = '$thisyear' 
     1182        FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' 
    11841183        AND post_type = 'post' AND post_status = 'publish' 
    1185         AND post_date < '" . current_time('mysql') . '\'', ARRAY_N); 
     1184        AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N); 
    11861185    if ( $dayswithposts ) { 
    11871186        foreach ( (array) $dayswithposts as $daywith ) { 
     
    12001199    $ak_post_titles = $wpdb->get_results("SELECT ID, post_title, DAYOFMONTH(post_date) as dom " 
    12011200        ."FROM $wpdb->posts " 
    1202         ."WHERE YEAR(post_date) = '$thisyear' " 
    1203         ."AND MONTH(post_date) = '$thismonth' " 
    1204         ."AND post_date < '".current_time('mysql')."' " 
     1201        ."WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' " 
     1202        ."AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59' " 
    12051203        ."AND post_type = 'post' AND post_status = 'publish'" 
    12061204    ); 
Note: See TracChangeset for help on using the changeset viewer.