From ee79c9e7d0e8531c3ac90fc476c2ee5ef0b43bf1 Mon Sep 17 00:00:00 2001 From: Mark Jaquith Date: Fri, 11 Dec 2009 23:29:19 +0000 Subject: [PATCH] Optimize Whoa Cowboy query. Only look back one hour. props mdawaffe. fixes #4366 git-svn-id: https://develop.svn.wordpress.org/trunk@12376 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/comment.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wp-includes/comment.php b/wp-includes/comment.php index 6e7092ca6b..98333d4265 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -550,7 +550,8 @@ function check_comment_flood_db( $ip, $email, $date ) { global $wpdb; if ( current_user_can( 'manage_options' ) ) return; // don't throttle admins - if ( $lasttime = $wpdb->get_var( $wpdb->prepare("SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_author_IP = %s OR comment_author_email = %s ORDER BY comment_date DESC LIMIT 1", $ip, $email) ) ) { + $hour_ago = gmdate( 'Y-m-d H:i:s', time() - 3600 ); + if ( $lasttime = $wpdb->get_var( $wpdb->prepare( "SELECT `comment_date_gmt` FROM `$wpdb->comments` WHERE `comment_date_gmt` >= %s AND ( `comment_author_IP` = %s OR `comment_author_email` = %s ) ORDER BY `comment_date_gmt` DESC LIMIT 1", $hour_ago, $ip, $email ) ) ) { $time_lastcomment = mysql2date('U', $lasttime, false); $time_newcomment = mysql2date('U', $date, false); $flood_die = apply_filters('comment_flood_filter', false, $time_lastcomment, $time_newcomment);