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

git-svn-id: http://svn.automattic.com/wordpress/trunk@6610 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-01-14 05:59:39 +00:00
parent 8c55d60d5b
commit 74cad1dac8

View File

@ -199,24 +199,26 @@ function get_commentdata( $comment_ID, $no_cache = 0, $include_unapproved = fals
*/
function get_lastcommentmodified($timezone = 'server') {
global $cache_lastcommentmodified, $wpdb;
if ( isset($cache_lastcommentmodified[$timezone]) )
return $cache_lastcommentmodified[$timezone];
$add_seconds_server = date('Z');
$now = current_time('mysql', 1);
if ( !isset($cache_lastcommentmodified[$timezone]) ) {
switch ( strtolower($timezone)) {
case 'gmt':
$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));
break;
case 'blog':
$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));
break;
case 'server':
$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));
break;
}
$cache_lastcommentmodified[$timezone] = $lastcommentmodified;
} else {
$lastcommentmodified = $cache_lastcommentmodified[$timezone];
switch ( strtolower($timezone)) {
case 'gmt':
$lastcommentmodified = $wpdb->get_var("SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1");
break;
case 'blog':
$lastcommentmodified = $wpdb->get_var("SELECT comment_date FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1");
break;
case 'server':
$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));
break;
}
$cache_lastcommentmodified[$timezone] = $lastcommentmodified;
return $lastcommentmodified;
}