Changeset 6610

Show
Ignore:
Timestamp:
01/14/08 05:59:39 (8 months ago)
Author:
ryan
Message:

Eliminate comment_date_gmt <= now from get_lastcommentmodified() queries. fixes #5650

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wp-includes/comment.php

    r6603 r6610  
    200200function get_lastcommentmodified($timezone = 'server') { 
    201201    global $cache_lastcommentmodified, $wpdb; 
     202 
     203    if ( isset($cache_lastcommentmodified[$timezone]) ) 
     204        return $cache_lastcommentmodified[$timezone]; 
     205 
    202206    $add_seconds_server = date('Z'); 
    203     $now = current_time('mysql', 1); 
    204     if ( !isset($cache_lastcommentmodified[$timezone]) ) { 
    205         switch ( strtolower($timezone)) { 
    206             case 'gmt': 
    207                 $lastcommentmodified = $wpdb->get_var($wpdb->prepare("SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_date_gmt <= %s AND comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1", $now)); 
    208                 break; 
    209             case 'blog': 
    210                 $lastcommentmodified = $wpdb->get_var($wpdb->prepare("SELECT comment_date FROM $wpdb->comments WHERE comment_date_gmt <= %s AND comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1", $now)); 
    211                 break; 
    212             case 'server': 
    213                 $lastcommentmodified = $wpdb->get_var($wpdb->prepare("SELECT DATE_ADD(comment_date_gmt, INTERVAL %s SECOND) FROM $wpdb->comments WHERE comment_date_gmt <= %s AND comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1", $add_seconds_server, $now)); 
    214                 break; 
    215         } 
    216         $cache_lastcommentmodified[$timezone] = $lastcommentmodified; 
    217     } else { 
    218         $lastcommentmodified = $cache_lastcommentmodified[$timezone]; 
    219     } 
     207 
     208    switch ( strtolower($timezone)) { 
     209        case 'gmt': 
     210            $lastcommentmodified = $wpdb->get_var("SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1"); 
     211            break; 
     212        case 'blog': 
     213            $lastcommentmodified = $wpdb->get_var("SELECT comment_date FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1"); 
     214            break; 
     215        case 'server': 
     216            $lastcommentmodified = $wpdb->get_var($wpdb->prepare("SELECT DATE_ADD(comment_date_gmt, INTERVAL %s SECOND) FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1", $add_seconds_server)); 
     217            break; 
     218    } 
     219 
     220    $cache_lastcommentmodified[$timezone] = $lastcommentmodified; 
     221 
    220222    return $lastcommentmodified; 
    221223}